How to detect HTML <canvas> is not Supported by JavaScript? Last Updated : 11 Oct, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report To detect if the HTML5 <canvas> element is supported by JavaScript, the existence of the getContext method is checked. This method is essential for rendering graphics on the canvas.Approach: Using getContext() methodThe getContext() method retrieves the drawing context of a canvas element and returns null if the context identifier is unsupported.A new canvas element is created using document.createElement(), and getContext('2d') checks for a two-dimensional rendering context.Double negation (!!) is used to convert the returned value to a boolean, where null becomes false and any non-null value becomes true.The boolean result indicates whether HTML5 canvas is supported in the browser.Example 1: html <!DOCTYPE html> <html> <head> <title> How to detect HTML 5 canvas is not supported by JavaScript? </title> </head> <body> <h1 style="color: green"> GeeksforGeeks </h1> <b> How to detect that HTML5 <canvas> is not supported by JavaScript? </b> <p> Click on the button to check for Canvas support </p> <p> Canvas is supported: <span class="output"></span> </p> <button onclick="checkCanvas()"> Check for canvas </button> <script type="text/javascript"> function checkCanvas() { canvasElem = document.createElement('canvas'); isSupported = !!canvasElem.getContext('2d'); document.querySelector('.output').textContent = isSupported; } </script> </body> </html> Output:Example 2: html <!DOCTYPE html> <html> <head> <title> How to detect HTML 5 canvas is not supported by JavaScript? </title> </head> <body> <h1 style="color: green"> GeeksforGeeks </h1> <b> How to detect that HTML5 <canvas> is not supported by JavaScript? </b> <p> Click on the button to check for Canvas support </p> <p> Canvas is supported: <span class="output"></span> </p> <button onclick="checkCanvas()"> Check for canvas </button> <script type="text/javascript"> function checkCanvas() { isSupported = !!window.HTMLCanvasElement; document.querySelector('.output').textContent = isSupported; } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to find whether browser supports JavaScript or not ? S sayantanm19 Follow Improve Article Tags : JavaScript Web Technologies HTML-Canvas JavaScript-Questions Similar Reads How to detect HTML 5 is supported or not in the browser ? HTML 5 is the latest standard of HTML that includes many new changes and features. HTML 5 support can be detected by using three approaches:Method 1: Checking for Geolocation support: The Geolocation API was added in HTML5. It is used for identifying the user's location. The presence of this API cou 4 min read How to check if a string is html or not using JavaScript? The task is to validate whether the given string is valid HTML or not using JavaScript. we're going to discuss a few techniques. Approach Get the HTML string into a variable.Create a RegExp which checks for the validation.RegExp should follow the rules of creating an HTML document. Example 1: In thi 2 min read How to check if CSS property is supported in browser using JavaScript ? Few CSS properties are not supported in some browsers, thus it is required to check whether a CSS property & its value are supported in the current browser. We can find it using JavaScript using CSS.supports() method. Syntax: supports(propertyName, value) supports(condition) There are two distin 2 min read How to check a JavaScript Object is a DOM Object ? Checking if a JavaScript object is a DOM object involves verifying whether the object represents an element or component within the Document Object Model (DOM) of an HTML or XML document. This can be done by checking if the object is an instance of Node, Element, or other specific DOM interfaces.Wha 2 min read How to find whether browser supports JavaScript or not ? We will discuss how to find whether our Browser supports JavaScript or not. For this, we need to use the <noscript> tag, which defines an alternate text to be displayed to users who have disabled <script> tag in their Browsers. Since JavaScript is written inside <script> tag in HTM 2 min read How to check whether the background image is loaded or not using JavaScript ? In this article, we will check whether the background image is loaded or not using JavaScript. In JavaScript, onload event is used to check whether a window is loaded or not. Similarly, we can use that event to check whether a particular element has loaded or not. There are two ways in which we can 2 min read Like