JavaScript – Check if a browser supports HTML5 Canvas or not
The below code shows you how to check if a browser supports HTML5 Canvas or not in JavaScript. We simply check the getContext
method of the Canvas object element.
The code looks simple as this:
html5-canvas.js
function isCanvasSupported() {
return !!document.createElement('canvas').getContext;
}
Use the function:
if (isCanvasSupported()) {
console.log('The browser supports HTML5 Canvas');
} else {
console.log('The browser does not support HTML5 Canvas');
}