JS Judging Browser type

Source: Internet
Author: User

Use navigator.useragent and to judge

PC side:

<script type= "Text/javascript" >
var ua=navigator.useragent.tolowercase ();
if (Ua.match (/webkit/i)) {
Alert ("Chrome");
}else if (Ua.match (/firefox/i)) {
Alert ("Firefox");
}
else if (Ua.match (/opera/i)) {
Alert ("opera");
}else if (Ua.match ("Trident")) {
Alert ("IE");
}
</script>

Mobile side:

<script type= "Text/javascript" >
var ua=navigator.useragent.tolowercase ();
var Neihe=document.getelementbyid (' Neihe ');
if (Ua.match (/qq/i)) {
Neihe.innerhtml= "QQ";
}else if (Ua.match (/micromessenger/i)) {
Neihe.innerhtml= "";
}else if (Ua.match (/oppo/i)) {
Neihe.innerhtml= "OPPO";
}else if (Ua.match (/iphone/i) | | Ua.match (/ipad/i)) {
Neihe.innerhtml= "Safari";
}else if (Ua.match (/opera/i)) {
Neihe.innerhtml= "Opera";
}
</script>

For Navigator.useragent, refer to Http://www.runoob.com/jsref/prop-nav-useragent.html

Note The match () method retrieves the string Object to find one or more text that matches the regexp. The behavior of this method depends to a large extent on whether RegExp has a flag g. If RegExp does not have a flag G, then the match () method can only perform a match in Stringobject. If no matching text is found, match () returns NULL. Otherwise, it returns an array that holds information about the matching text it finds.

JS Judging Browser type

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.