Use JS to determine browser type (whether Ie,firefox,opera browser) _javascript skills

Source: Internet
Author: User

Now there are probably several browsers, individual preferences are also different, so the use of different browsers! The people we develop often have to add a judgment that it is impossible for certain functions to be used properly. If you don't make a judgment, you'll get us some trouble! Although perhaps everyone's preferences are different! The system is also different! Some people like to use IE, Firefox, and some people like to use Tencent Tt,maxthon and so on. Although the name may have many kinds of, but the kernel we know that there is no problem. such as the IE kernel: Ie,maxthon,tt are. And of course, Netscape's core! See how people Judge!

Because of this problem during development. So look for information and their own summary of the following JS code:

The code is as follows:

Copy Code code 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 browsing the Web with other browsers! ')}
</script>

Or the following code can also be
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
&LT;TITLE&GT;JS Check what is the browser </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 are using Firefox!") Version is: firefox/"+versionname+" "<br>");
}
else {
var name=navigator.appname;
if (name== "Microsoft Internet Explorer") {document.write ("You are using IE browser!") ");}
}
}
</script>
<body onload= "Checkfirefoxorie ();" >
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.