Use js to determine whether the browser type of of is IE Firefox Opera or not

  • 2020-03-29 23:58:55
  • OfStack

Now there are probably several kinds of browsers, each person's preferences are different, so also use different browsers! The people that we develop often have to make a judgment that something might not work. If you don't add a judgment will cause some trouble for everyone! Although we may have different preferences! Different systems! Some people like to use Internet explorer, firefox, others like to use tencent tt, maxthon and so on. There may be many different names, but the kernel is fine as long as we know it. IE kernel: IE, maxthon,tt are all. And of course the netscape kernel! See everybody how to judge!

Due to this problem during development. Therefore, I found the data and summarized the following JS code:

The code is as follows:


<script language="JavaScript" type="text/javascript">
if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)){alert(' You are using IE')}else
    if (navigator.userAgent.indexOf('Firefox') >= 0){alert(' You are using Firefox')}else
        if (navigator.userAgent.indexOf('Opera') >= 0){alert(' You are using Opera')}else
{alert(' You are using another browser to browse the web! ')}
</script>

Or the following code can also be used

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS What browser is check </title>
<script language="JavaScript" type="text/javascript">
function checkFirefoxOrIE(){
userAgent=window.navigator.userAgent.toLowerCase();
if(userAgent.indexOf("firefox")>=1){
Findex=userAgent.indexOf("firefox/");
versionName=userAgent.substr(Findex+"Firefox/".length,3);
document.write(" You're using firefox! Version is: Firefox/"+versionName+"<br>");
}
else {
    var name=navigator.appName;
    if(name=="Microsoft Internet Explorer"){document.write(" You are using IE The browser! ");}
    }
}
</script>
</head>
<body onload="checkFirefoxOrIE();">
</body>
</html>


Related articles: