如何切换QQ浏览器内核

301 阅读1分钟

window.external对象中有两个方法

currentcore():获取到当前浏览器内核模式------ 1是兼容模式、2是极速模式

** setcore()** :设置浏览器当前内核模式。setcore(1)将内核设置为兼容模式;setcore(2)将内核设置为极速模式。

setcore 方法执行后,如果改变了内核模式,会自动刷新当前页面。如果没有改变,还是原来的模式,则不会刷新。

    //检测如果是QQ浏览器兼容模式,则强制切换为极速模式
    var explorer = window.navigator.userAgent || '';
    if(explorer.toLowerCase().indexOf("qqbrowser") >= 0 && window.external){
      var curCore  = 'currentcore' in window.external ? window.external.currentcore() : 1;//极速是2 兼容是1
      if(curCore === 1 && 'setcore' in window.external){
        window.external.setcore(2);
      }
    }