Home > Web Front-end > JS Tutorial > How to get the browser type and version with javascript (get the browser version with js)_Basic knowledge

How to get the browser type and version with javascript (get the browser version with js)_Basic knowledge

WBOY
Release: 2016-05-16 16:55:38
Original
978 people have browsed it

复制代码 代码如下:

function getExplorerInfo() {
 var explorer = window.navigator.userAgent.toLowerCase() ;
 //ie
 if (explorer.indexOf("msie") >= 0) {
    var ver=explorer.match(/msie ([d.] )/)[1];
    return {type:"IE",version:ver};
 }
 //firefox
 else if (explorer.indexOf("firefox") >= 0) {
    var ver=explorer.match(/firefox/([d.] )/)[1];
    return {type:"Firefox",version:ver};
 }
 //Chrome
 else if(explorer.indexOf("chrome") >= 0){
    var ver=explorer.match(/chrome/([d.] )/)[1];
     return {type:"Chrome",version:ver};
 }
 //Opera
 else if(explorer.indexOf("opera") >= 0){
 var ver=explorer.match(/opera.([d.] )/)[1];
 return {type:"Opera",version:ver};
 }
 //Safari
 else if(explorer.indexOf("Safari") >= 0){
 var ver=explorer.match(/version/([d.] )/)[1];
 return {type:"Safari",version:ver};
 }
 }
 alert("type:" getExplorerInfo().type "nversion:" getExplorerInfo().version);
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template