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');
}

0 0 vote
Article Rating
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x