JS Navigator Object

Source: Internet
Author: User

Original: https://www.cnblogs.com/huyihao/p/6003110.html

The Navigator object contains information about the browser.

Many times we need to determine the browser and platform on which the page is located, and Navigator provides us with the convenience

Navigator Common object properties are as follows:

Properties Description
appCodeName Returns the code name of the browser.
appMinorVersion Returns the secondary version of the browser.
AppName Returns the name of the browser.
AppVersion Returns the platform and version information for the browser.
Browserlanguage Returns the language of the current browser.
cookieenabled Returns a Boolean value that indicates whether cookies are enabled in the browser.
Cpuclass Returns the CPU level of the browser system.
OnLine Returns a Boolean value that indicates whether the system is in offline mode.
Platform Returns the operating system platform on which the browser is running.
Systemlanguage Returns the default language used by the OS.
UserAgent Returns the value of the user-agent header of the server sent by the client.
Userlanguage Returns the natural language setting of the OS.

We use more of his useragent, often need to judge the situation has:

(1) PC or mobile

(2) Android or iOS

(3) Type of browser

Example code:

 1 var browser={2 versions:function () {3 var u = navigator.useragent, app = navigator.appversion; 4 r Eturn {//Mobile terminal browser version information 5 trident:u.indexof (' Trident ') >-1,//ie core 6 Presto:u.inde XOf (' Presto ') >-1,//opera core 7 webkit:u.indexof (' AppleWebKit ') >-1,//Apple, Google kernel 8 gecko : U.indexof (' Gecko ') >-1 && u.indexof (' khtml ') = =-1,//Firefox core 9 Mobile:!! U.match (/applewebkit.*mobile.*/),//Is mobile terminal iOS:!! U.match (/\ (i[^;] +;( U;)? Cpu.+mac OS x/),//ios terminal Android:u.indexof (' Android ') >-1 | |                U.indexof (' Linux ') >-1,//android terminal or UC Browser iphone:u.indexof (' iphone ') >-1,//whether for IPhone or Qqhd browser 13 Ipad:u.indexof (' IPad ') >-1,//whether IPAD14 webapp:u.indexof (' Safari ') = = 1//Whether the Web should program, no header department and bottom of};16} (), Language: (Navigator.browserlanguage | | navigator.language). toLowerCase () 18}

Determine if the mobile side

1 if (browser.versions.mobile) {2       console.log (' I am mobile ');      9 ·

You can also judge in another way

1 var s=document.hasownproperty ("Ontouchstart");//Computer returns FALSE, cell phone is true2 console.log (s);

Determine whether Android or iOS

1 if (Browser.versions.ios) {2      console.log (' I am iOS '); 3}4 if (browser.version.andriod) {5      console.log (' I am Android '); 6}

Determine the type of browser

1 if (browser.versions.trident) {2     console.log (' I am ie '); 3} 4 if (Browser.versions.presto) {5     console.log (' I am opera '); 6} 7 if (browser.versions.webKit) {8     console.log (' I am Apple and Google '); 9}10 if (Browser.versions.gecko) {     One Console.log (' I am Firefox '); 12}

JS Navigator Object

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.