Detailed description of window. navigator in javascript Host object, javascriptnavigator

Source: Internet
Author: User

Detailed description of window. navigator in javascript Host object, javascriptnavigator

Window. navigator is an object that reflects the information about the browser and its functions.

// Check the browser version information function getBrowserInfo () {var Sys ={}; var ua = window. navigator. userAgent. toLowerCase (); var re =/(msie | firefox | chrome | opera | version ). *? ([\ D.] +)/; var m = ua. match (re); Sys. browser = m [1]. replace (/version/, "'safari"); Sys. ver = m [2]; return Sys;} var BomInfo = getBrowserInfo; console. log (BomInfo ());

How can I determine whether it is ie?

var navigatorName = "Microsoft Internet Explorer"; var isIE = false;  if( window.navigator.appName == navigatorName ){    isIE = true;    alert("ie")  }else{    alert("not ie")  }  

Another method is as follows:

If (window. addEventListener) {alert ("not ie");} else if (window. attachEvent) {alert ("is ie");} else {alert ("this happens when browsers of earlier versions that do not support DHTML are generally supported now )")}

Determine the device type:

Function browerType () {var sUserAgent = navigator. userAgent. toLowerCase (); // set the browser's user proxy to lowercase, and then match var isIpad = sUserAgent. match (/ipad/I) = "ipad"; // or use the indexOf method to match var isIphoneOs = sUserAgent. match (/iphone OS/I) = "iphone"; var isMidp = sUserAgent. match (/midp/I) = "midp"; // mobile information device description MIDP is a set of Java application programming interfaces. It is applicable to the Saipan system var isUc7 = sUserAgent. match (/rv: 1.2.3.4/I) = "rv: 1.2.3.4"; // CVS label var isUc = sUserAgent. match (/ucweb/I) = "ucweb"; var isAndroid = sUserAgent. match (/android/I) = "android"; var isCe = sUserAgent. match (/windows ce/I) = "windows ce"; var isWM = sUserAgent. match (/windows mobil/I) = "windows mobil"; if (isIpad | isIphoneOs | isMidp | isUc7 | isUc | isAndroid | isCe | isWM) {alert ('this device is a mobile device'); // do something} else {alert ('this device is a PC device '); // do something} browerType ();

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.