Canvas and emulation

For clients which do not support native canvas, CrossBrowdy provides automatic fallback to
Adobe Flash emulation with FlashCanvas,
Microsoft Silverlight emulation with SLCanvas,
VML emulation with ExplorerCanvas (reinforced with canvas-text)
and DHTML (DOM elements) emulation with CanBox.

When no emulation method is forced on purpose, CrossBrowdy will automatically calculate and use the best emulation method for the current client.

To make the VML emulation work without errors (using
ExplorerCanvas), it is recommended to always load
FlashCanvas (which already includes
ExplorerCanvas) in your HTML code (without using lazy-load, as
ExplorerCanvas does not support it).
This is recommended even when we are not going to use
Adobe Flash emulation with FlashCanvas.
This is an example (should be placed before loading the main "CrossBrowdy" script):

For legacy clients not compatible with native canvas, some emulation methods will require you to create the canvas element in HTML directly (instead of dynamically with JavaScript). Doing so will maximize compatibility with most clients:

<canvas id="canvas_id">if you read this, canvas is not working</canvas><!-- Some emulation methods will require the canvas element created in HTML (not dynamically by JavaScript). -->

Here is the JavaScript code with some examples creating canvas (CB_Canvas) objects:

Since some canvas emulation methods can be asynchronous, it is recommended to always use callbacks when creating the canvas (CB_Canvas) object and start working with it only once it loads (when the "onLoad" function is called). Here is an example with more methods:

Finally, the CB_Canvas class provides some interesting static methods (most times they will be not needed as they are already called internally when creating a new object):

//Checks whether canvas would be need to be emulated or not:
if (CB_Canvas.needsEmulation()) { CB_console("Canvas should be emulated!"); }
else { CB_console("Canvas is supported natively! There is no need for any emulation method."); }
//Checks what emulation methods are supported, one by one:
if (CB_Canvas.supportsEmulationMethod("FLASH")) { CB_console("Canvas can be emulated through FLASH"); }
if (CB_Canvas.supportsEmulationMethod("VML")) { CB_console("Canvas can be emulated through VML"); }
if (CB_Canvas.supportsEmulationMethod("SILVERLIGHT")) { CB_console("Canvas can be emulated through SILVERLIGHT"); }
if (CB_Canvas.supportsEmulationMethod("DHTML")) { CB_console("Canvas can be emulated through DHTML (DOM)"); }
//Calculate and returns the best canvas emulation method (can return "NONE", "FLASH", "SILVERLIGHT", "VML" or "DHTML"):
var bestEmulationMethod = CB_Canvas.bestEmulation(); //Calculates the best among all possible ones.
var bestEmulationMethod_2 = CB_Canvas.bestEmulation(["FLASH", "SILVERLIGHT"]); //Calculates the best between "FLASH" and "SILVERLIGHT".