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.