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

javascript browser detection code simplified version_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:33:11828browse
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
}
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