JavaScript useragent get user browser type

Source: Internet
Author: User

Web effects useragent Get user Browser type

var useragent = navigator.userAgent.toLowerCase ();

useragent property syntax
Navigator.useragent;
UserAgent Property Description

Attribute description
appCodeName Gets the code name of the browser.
appMinorVersion gets the minor version value of the application.
AppName Gets the name of the browser.
AppVersion Gets the platform and version of the browser running.
Browserlanguage gets the current language of the browser.
Cookieenabled gets whether the client's permanent cookie is enabled in the browser. Permanent cookies are stored on the client computer.
Cpuclass gets a string indicating the CPU level.
Online Gets a value that indicates whether the system is in global offline mode.
Platform gets the user's operating system name.
Systemlanguage Gets the default language that the operating system applies to.
UserAgent gets the string equivalent to the HTTP User agent request header.
Userlanguage gets the natural language settings for the operating system.

Usually use the Navigator.useragent property to judge the browser and operating system that the user uses, the operating system usage statistics and browser usage statistics of the dream Capital are obtained by the useragent attribute

var IS_WEBTV = useragent.indexof (' WebTV ')!=-1;


The indexof () method returns the location of the first occurrence of a specified string value in a string.

Grammar
Stringobject.indexof (searchvalue,fromindex) parameter description
Searchvalue required. A string value that requires retrieval.
Fromindex an optional integer parameter. Specify where to start retrieving in the string. Its legal value is 0 to stringobject.length-1. If this argument is omitted, it is retrieved from the first character of the string.

Description
This method retrieves the string stringobject from beginning to end to see if it contains substring searchvalue. The location at which to start retrieving is at the fromindex of the string or at the beginning of the string (no fromindex is specified). If a searchvalue is found, it returns the position of the first occurrence of searchvalue. The character position in Stringobject is starting at 0.

var Is_kon = useragent.indexof (' Konqueror ')!=-1;
var is_mac = useragent.indexof (' mac ')!=-1;
var is_saf = useragent.indexof (' AppleWebKit ')!=-1 | | navigator.vendor = = ' Apple Computer, Inc. ';
var is_opera = useragent.indexof (' opera ')!=-1 && opera.version ();
var Is_moz = (Navigator.product = = ' Gecko ' &&!is_saf) && useragent.substr (' Firefox ') + 8, 3);
var Is_ns = useragent.indexof (' compatible ') = = 1 && useragent.indexof (' Mozilla ')!=-1 &&!is_opera &&!IS_WEBTV &&!is_saf;
var is_ie = (useragent.indexof (' MSIE ')!=-1 &&!is_opera &&!is_saf &&!IS_WEBTV) && Useragent.substr (Useragent.indexof (' msie ') + 5, 3);
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.