Use JS to determine the operating system and browser type

Source: Internet
Author: User

Determine the JS code of the operating system and browser

The Navigator.userAgent:userAgent property is a read-only string that declares the value of the user agent header used by the browser for HTTP requests.
The Navigator.platform:platform property is a read-only string that declares the operating system and/or hardware platform on which the browser is running.

Determine the operating system type
Win operating system

1     Navigator.platform = = "Win32"2     navigator.platform = = "Windows"

Win2000 Operating System

1 /windows NT 5.0/i.test (navigator.useragent)

WinXP operating System

1 /windows NT 5.1/i.test (navigator.useragent)

WIN2003 Operating System

1 /windows NT 5.2/i.test (navigator.useragent)

WinVista Operating System

1  /windows NT 6.0/i.test (navigator.useragent)

Win7 Operating System

1 /windows NT 6.1/i.test (navigator.useragent)

Mac operating System

1     Navigator.platform = = "mac68k"2     navigator.platform = = "MACPPC"3     navigator.platform = = " Macintosh "4     navigator.platform = =" Macintel "

UNIX Operating system

1 navigator.platform = = "X11"

Linux operating system

1 /linux/i.test (navigator.useragent)

Andorid Operating System

1     if (/linux/i.test (navigator.  useragent) {2         if(/android/i.test (navigator.useragent).  toLowerCase ())) {3             return "Android"; 4         }5     }




Determine browser type
IE Browser:

1 /ie/i.test (Navigator.userAgent.toLowerCase ());

Firefox browser

1 /firefox/i.test (Navigator.userAgent.toLowerCase ());

Google Chrome

1 /chrome/i.test (Navigator.userAgent.toLowerCase ());

Opera browser

1 /opera/i.test (Navigator.userAgent.toLowerCase ());

Safari browser

1  /safari/i.test (Navigator.userAgent.toLowerCase ());

Browser

1 /micromessenger/i.test (Navigator.userAgent.toLowerCase ());



Use JS to determine the operating system and browser type

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.