zoukankan      html  css  js  c++  java
  • 判断不同浏览器,加载不同的css和js文件

    在低版本的IE中,条件注释还有效果,但是在ie9,10,11浏览器中,条件注释不起作用。

    在网上找了个校验ie的方法。

    function isIE(){
      if (window.ActiveXObject || "ActiveXObject" in window){
        alert('is ie')
      }else{
        alert(not ie')
      }
    }
    isIE();


    IE下才有这个对象ActiveXObject

    当然我们也可以根据浏览器是否为IE,引入不同的js和css文件。

    这里网上有个例子。

    var linkNode = document.createElement("link"),scriptNode = document.createElement("script");  
    linkNode.setAttribute("rel","stylesheet");  
    linkNode.setAttribute("type","text/css");  
    scriptNode.setAttribute("type", "text/javascript");  

    if(getBrowser()=="IE"){  
        linkNode.setAttribute("href","css/index-ie.css");  
        scriptNode.setAttribute("src", "js/index-ie.js");  
    }else if(getBrowser()=="Firefox"){  
        linkNode.setAttribute("href","css/index-firefox.css");  
        scriptNode.setAttribute("src", "js/index-firefox.js");  
    }else if(getBrowser()=="Opera"){  
        linkNode.setAttribute("href","css/index-opera.css");  
        scriptNode.setAttribute("src", "js/index-opera.js");  
    }else if(getBrowser()=="Chrome"){  
        linkNode.setAttribute("href","css/index-chrome.css");  
        scriptNode.setAttribute("src", "js/index-chrome.js");  
    }else if(getBrowser()=="Safari"){  
        linkNode.setAttribute("href","css/index-safari.css");  
        scriptNode.setAttribute("src", "js/index-safari.js");  
    }  
    document.head.appendChild(linkNode);  
    document.head.appendChild(scriptNode);

    即先生成link和script标签,给类型,再根据浏览器的不同给出不同的路径
    是ie就引入polyfill.js和browser.js,并且vue的script标签类型为text/babel,非IE浏览器下,不需要引入polyfill.js和browser.js,vue的script标签类型为text/javascript,即最传统的类型。

    function isIE(src){
      var polyfill = document.createElement("script");
      var browser = document.createElement("script");
      var myVuejs = document.createElement("script");
      polyfill.setAttribute("src", "../../js/bootshop/js/polyfill.js");
      browser.setAttribute("src", "../../js/bootshop/js/browser.min.js");
      myVuejs.setAttribute("src", src);

      if (window.ActiveXObject || "ActiveXObject" in window){
        myVuejs.setAttribute("type", "text/babel");
        document.head.appendChild(polyfill);
        document.head.appendChild(browser);
        document.head.appendChild(myVuejs);
      }else{
        document.head.appendChild(myVuejs);
      }
    }

    原文:https://blog.csdn.net/cofecode/article/details/80175179

  • 相关阅读:
    从json中获取自己想要的属性
    对称加密解密
    springboot 读取resource目录下的文件
    安装nginx 配置了ssl 启动报错
    复利计算--4.0 单元测试之JAVA版-软件工程
    《构建之法》前三章读后感
    单利 复利计算器程序1.0 2.0 3.0 [ 合 ] 之 WEB
    操作系统 实验一 命令解释程序的编写
    单利 复利计算器程序1.0 2.0 3.0 [ 合 ] 之 C语言
    统计实验数据 总结实验结果
  • 原文地址:https://www.cnblogs.com/alexguoyihao/p/10195436.html
Copyright © 2011-2022 走看看