Friday, February 24, 2012

Checking for Browser Support HTML 5

Checking for Browser Support

Before you use the canvas element, make sure there is support in the browser or not. Using this way, you can provide some alternate text in case there is no support in their antique browser.
Example:
try {
document.createElement("canvasId").getContext("2d");
document.getElementById("browsersupport").innerHTML =
"Wow… HTML5 Canvas is supported in your browser.";
} catch (e) {
document.getElementById("browsersupport ").innerHTML = "Sorry… HTML5 Canvas is not supported
in your browser.";
}

In this example, you try to create a canvas object and access its context. If there is an error, you will
catch it and know that Canvas is not supported. A previously defined support element on the page is
updated with a suitable message to reflect whether there is browser support or not.
This test will indicate whether the canvas element itself is supported by the browser. It will not
indicate which capabilities of the Canvas are supported. At the time of this writing, the API is stable and
well-supported, so this should generally not be an issue to worry about.

No comments:

Post a Comment