Home > Web Front-end > JS Tutorial > javascript browser detection code simplified version_javascript skills

javascript browser detection code simplified version_javascript skills

WBOY
Release: 2016-05-16 18:33:11
Original
834 people have browsed it
Copy code The code is as follows:

/*written by xp in 8z at Mar 4,2010.QQ: 251089096*/
var sUserAgent = navigator.userAgent;
var isIE=isIE6=isIE7=isIE8=isFirefox=false;
if(sUserAgent.indexOf("MSIE") > -1){
isIE = true;
var version = sUserAgent.substr(sUserAgent.indexOf("MSIE") 5,3);
if(version == "6.0"){isIE6=true;}
if (version == "7.0"){isIE7=true;}
if(version == "8.0"){isIE8=true;}
}
if(sUserAgent.indexOf("Firefox") > ; -1){isFirefox=true;}

Usage guidelines:
Copy code The code is as follows :

if(isIE)
{
Statement body
}
if(isIE6)
{
Statement body
}
if(isIE7)
{
Statement body
}
if(isIE8)
{
Statement body
}
if(isFirefox)
{
Statement body
}
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