Home >Web Front-end >JS Tutorial >How to identify your browser's JavaScript engine

How to identify your browser's JavaScript engine

高洛峰
高洛峰Original
2016-11-28 13:24:121265browse

Available for both PC browsers and mobile browsers.

The principle is this js:

window.onload = function() {  
  var v8string = 'function%20javaEnabled%28%29%20%7B%20%5Bnative%20code%5D%20%7D';  
     
  if (window.devicePixelRatio)  //If WebKit browser  
  {  
     if (escape(navigator.javaEnabled.toString()) === v8string)  
     {  
        display('V8 detected');  
     }  
     else 
     {  
        display('JSC detected');  
     }  
  }  
  else {  
    display("Not a WebKit browser");  
  }  
     
  function display(msg) {  
    var p = document.createElement('p');  
    p.innerHTML = msg;  
    document.body.appendChild(p);  
  }  
     
};

First detect the WebKit-specific attribute devicePixelRatio, and then detect the implementation of the v8-specific javaEnabled function.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn