• IE8里判断当前网页显示模式


    我们知道IE8 的一个重要更新就是加入了标准模式(standards mode)的显示引擎,但IE8里面仍然保留以前IE版本的显示模式,比如Strict Mode 以及 Quirks mode, 我们统称之为兼容模式 (compatibility view)。 
    那么如何判断IE8 用什么模式显示当前网页呢? IE8 里面新加Javascript 函数 document.documentMode 能够很好帮助我们解决这个问题。
    document.documentMode  的返回值有3个,其含义如下:
    5 表示老版本IE的Quirks mode.
    7 表示老版本IE的Strict mode.
    8 表示IE8的标准模式 standards mode.
    document.documentMode  只有在IE8上有,对于老版本IE需要使用其他API。以下代码可以让你在所有版本IE下判断显示模式:
    view plaincopy to clipboardprint?
    engine = null;    
    if (window.navigator.appName == "Microsoft Internet Explorer")    
    {   
       // 当前浏览器是IE,下面判断具体的显示模式   
       if (document.documentMode) // IE8   
          engine = document.documentMode;   
       else // IE 5-7   
       {   
          engine = 5; //  quirks mode unless proven otherwise   
          if (document.compatMode)   
          {   
             if (document.compatMode == "CSS1Compat")   
                engine = 7; // standards mode   
          }   
       }   
       alert("IE的当前显示模式是" + engine);   
    }  
    engine = null; 
    if (window.navigator.appName == "Microsoft Internet Explorer") 
    {
       // 当前浏览器是IE,下面判断具体的显示模式
       if (document.documentMode) // IE8
          engine = document.documentMode;
       else // IE 5-7
       {
          engine = 5; //  quirks mode unless proven otherwise
          if (document.compatMode)
          {
             if (document.compatMode == "CSS1Compat")
                engine = 7; // standards mode
          }
       }
       alert("IE的当前显示模式是" + engine);
    }
     
    Tips:你可以在IE地址栏里面输入 javascript:alert(document.documentMode); 来查看当前网页的显示模式。
  • 相关阅读:
    环境变量配置1
    Golang 类型转换,断言和显式强制转换
    Goland could not launch process: decoding dwarf section info at offset 0x0: too short 解决方案
    用puttygen工具把私钥id_rsa转换成公钥id_rsa.ppk
    JetBrains GoLand 2018 激活码/ 注册码(最新破解方法)
    Go学习笔记(只有链接)
    linux中的ftp命令
    Linux的学习之路
    like语句百分号前置会使用到索引吗?
    记录下每月生活开支
  • 原文地址:https://www.cnblogs.com/douglasvegas/p/4761372.html
Copyright © 2020-2023  润新知