Read doctype with JavaScript

后端 未结 2 1063
你的背包
你的背包 2021-01-02 08:43

Is the doctype part of the DOM, and if so, is there a good cross-browser way to read it? I\'m not trying to do anything fancy. I just want to access the doctype informatio

相关标签:
2条回答
  • 2021-01-02 09:16

    If you're inspecting the DOCTYPE to determine if you're in quirksmode or not, this is known to be cross-browser:

    document.compatMode; // returns either "BackCompat" or "CSS1Compat"
    

    So you can do:

    var quirksmode = document.compatMode == "BackCompat";
    
    0 讨论(0)
  • document.doctype seems to be the (read-only) property you're looking for.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题