JavaScript ways to get browser information _javascript tips

Source: Internet
Author: User

Window has a navigator object that lets us know all about the browser. We can use a series of API functions to learn about the browser's information.

The JavaScript code is as follows:

Function message ()
{ 
txt = "<p> Browser code Name: + navigator.appcodename + </p>";
txt+= "<p> Browser name:" + navigator.appname + "</p>"; 
txt+= "<p> Browser platform and version:" + navigator.appversion + "</p>";
txt+= "<p> Whether to open cookies:" + navigator.cookieenabled + "</p>";
txt+= "<p> Operating system Platform:" + navigator.platform + "</p>"; txt+= "<p>user-agent Head value:" + navigator.useragent + "</p>"; 
document.getElementById ("Example"). Innerhtml=txt; 
if ((navigator.appname== "Netscape" | | navigator.appname== "Microsoft Internet Explorer") && (parsefloat ( navigator.appversion) (>=4))
{alert ("Your browser is advanced enough!") "); }
else 
{alert ("It's time to upgrade your browser!") ");
} 
}

We can use this function to inform the user whether the browser should update the browser, but also to help users know the relevant information about the browser

Basic information for each major browser

Landlord test almost current mainstream browser, of course, no matter how many browsers are trident,blink,gecko,webkit of these kinds of browser kernel, parsing will not have too much access, is attached to the relevant screenshots are as follows:

This is the edge.

IE11, the landlord did not use IE6, but should not have too much discrepancy

Safari, the landlord is Window System Safari version is relatively low

Sogou Browser, once the landlord has also been infatuated with it for some time!

QQ Browser (micro-letter version), compared to the force, now the landlord in addition to chrome with the most browsers, dual-core Trident and Blink,chrome core under the fast

360 Secure browser compatibility mode, with IE's Trident kernel

Firefox, not much said, Netscape genuine, developers must browser

Chrome. Now the most used by the landlord browser, Google is really good, the force is very

360 Secure browser speed mode, chrome core, fast

Code Result analysis

Ps:javascript access to browser address and parameter method

Use JavaScript to get URL information

Execute javascript to get URL Information code effect is as follows

Location.host=www. Dw. CN
location.hostname=www. Dw. CN
location.href=http://www. Dw.  cn/news/2010-1/201011820131610618.shtml
location.pathname=/news/2010-1/201011820131610618.shtml
Location.protocol=http:

Detailed description of window.location method get URL

Uniform Resource Locator (uniform Resource Locator, URL) The complete URL is composed of these parts:

Scheme://host:port/path?query#fragment

Scheme: Communication protocol

Commonly used Http,ftp,maito, etc.

Host: Hosts

Server (computer) domain Name System (DNS) host name or IP address.

Port: Port number

Integer, optional, omit when using the default port of the scheme, such as HTTP's default port is 80.

Path: Paths

A string separated by 0 or more "/" symbols, typically used to represent a directory or file address on a host.

Query: Querying

Optional for dynamic Web pages, such as using CGI, ISAPI, php/jsp/asp/asp. NET, and other technology-made pages, can have multiple parameters, separated by the "&" symbol, and the name and value of each parameter are separated by the "=" symbol.

Fragment: Pieces of information

A string that specifies the fragment in the network resource. For example, a Web page has multiple noun interpretations, which can be directly positioned to a noun interpretation using fragment. (also known as anchor points.)

Example:

1, Window.location.href

Entire URL string (in the browser is the complete address bar)

return value: http://www. Dw. Cn:80/index.asp?id=209#asp

2,window.location.protocol

The protocol part of the URL

Return value: http:

3,window.location.host

The host part of the URL,

return value: www. Dw. cn

4,window.location.port

The port portion of the URL. If you use the default port 80 (update: Even if you added: 80), the return value is not the default 80 but the null character.

This example returns a value: null

5,window.location.pathname

The path portion of the URL (that is, the file address)

return value:/index.asp

6,window.location.search

The query (Parameters) section. In addition to assigning values to dynamic languages, we can also give static pages and use JavaScript to get the value of a parameter that is believed to be

Return value:? id=209

7,window.location.hash

Anchor Point

return value: #asp

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.