JS method to detect visitor browser type

Source: Internet
Author: User


Detect in  browser

<script>
document.write (Navigator.userAgent.toLowerCase ());
</script>

Output to

mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;. NET CLR trident/4.0; inf opath.2; asktbptv/5.17.0.25589; Alexa toolbar)


Detect display as

mozilla/5.0 (Windows NT 5.1; rv:38.0) gecko/20100101 firefox/38.0
in FF browser

Displays

mozilla/5.0 (Windows NT 5.1) applewebkit/537.36 (khtml, like Gecko) in Google browser chrome/42.0.2311.152 safari/537.36


Why doesn't identify yourself? This is a little weird. The specific reason may be a business relationship, according to the above we know that different browsers will bring their own browser firefox/38.0 chrome/42.0.2311.152 so we can use this to determine the user browser type.



You probably know what's going on with the comments in the code above. Note: The Browser.version > 6 version in if can only be used for IE, the other browser version can not be so judged, there is no way to find a solution. If you want to make the If judgment successful and execute a section of HTML code, then you can fill in the {} after if the HTML converted to JS code. Here are a few typical browser judgment statements:


if (Browser.safari) {}/* Determines whether safari/
if (Browser.firefox) {}/* is judged to be Firefox
/if (browser.chrome) {}/* Whether it is for the chrome/
if (Browser.opera) {}/* to determine whether the opera
/if (browser.ie) {}/* is for IE */







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.