All HTML Tags supported by a Browser

后端 未结 4 1170
心在旅途
心在旅途 2020-12-11 02:23

Using JavaScript, is it possible to obtain a list of the tags that a browser supports?

4条回答
  •  时光说笑
    2020-12-11 03:21

    There is no general way but each element has specific way to see if it's supported

    Canvas element support:

    var canvasSupported = "getContext" in document.createElement("canvas");
    

    Input type support:

    var input = document.createElement("input");
    input.type = "color"
    var colorInputSupported = input.type === "color";
    //The above relies on the fact that type is enumerated and 
    //falls back to "text" with invalid value
    //The technique doesn't necessarily carry over to other properties
    

    Audio element support:

    var audioElementSupported = "play" in document.createElement("audio");
    

    Progress element support

    var progressElementSupported = "max" in document.createElement("progress");
    

提交回复
热议问题