This article mainly introduces the HTML5 Canvas method to test whether the browser supports Canvas. This article gives two native methods and a modernizr class library. Friends who need it can refer to it.
This article is translated from Steve Fulton & Jeff Fulton HTML5 Canvas, Chapter 1, Testing to See Whether the Browser Supports Canvas.
After getting a reference to the Canvas element on the HTML page, we need to test whether the element contains a context. The context of Canvas refers to the plane defined by the browser for painting. Simply put, if the context does not exist, Canvas will be in name only. There are several ways to test whether the browser supports Canvas. The first method is to check whether the getContext method of the Canvas element in the HTML page exists:
Copy the code