JS perfect identification IE, Firefox, Chrome, Safari browser

Source: Internet
Author: User

(turn) to determine whether IE browser is very simple, with navigator.appname to judge on the line. And Firefox, Chrome, Safari's navigator.appname output values are "Netscape", Now we use navigator.useragent this property to judge, because the Google Chrome navigator.useragent value contains the "Safari" string and the Safari browser does not contain chrome, So we can use this distinction to differentiate between safari and chrome. The complete code is 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=utf-8" /><title>js perfectly identifies IE, Firefox, Chrome, Safari </title><script>function BrowserType (){var osobject = "";if (navigator.userAgent.indexOf ("MSIE") >0) {osobject = "MSIE";}if (Isfirefox=navigator.useragent.indexof ("Firefox") >0) {osobject = "Firefox";}if (Issafari=navigator.useragent.indexof ("Safari") >0&&navigator.useragent.indexof ("Chrome") <0 ) {osobject = "Safari";}if (Iscamino=navigator.useragent.indexof ("Chrome") >0) {osobject = "Chrome";}return osobject;}function Msg (){document.getElementById ("msg"). InnerHTML = "}</script><body onload= "MSG ()" ><span id= "msg" ></span></body>
Related Article

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.