How to use JavaScript to obtain browser Information _ javascript skills

Source: Internet
Author: User
This article describes how to use JavaScript to obtain browser information and how to obtain browser addresses and parameters. For more information about browser information, see the navigator object in Window. we can use a series of API functions to learn browser information.

The JavaScript code is as follows:

Function message () {txt ="

Browser code name: "+ navigator. appCodeName +"

"; Txt + ="

Browser name: "+ navigator. appName +"

"; Txt + ="

Browser platform and version: "+ navigator. appVersion +"

"; Txt + ="

Enable cookie: "+ navigator. cookieEnabled +"

"; Txt + ="

Operating System platform: "+ navigator. platform +"

"; Txt + ="

User-agent header value: "+ navigator. userAgent +"

"; Document. getElementById ("example "). innerHTML = txt; if (navigator. appName = "Netscape" | navigator. appName = "Microsoft Internet Explorer") & (parseFloat (navigator. appVersion)> = 4) {alert ("your browser is advanced! ");} Else {alert (" it's time to upgrade your browser! ");}}

We can use this function to notify the user browser whether to update the browser, and also to help the user know the browser information.

Basic information of various browsers

The author tested almost mainstream browsers. Of course, no matter how many browsers are Trident, Blink, Gecko, and Webkit browsers, there will not be too many differences in resolution. The relevant information is attached as follows:

This is an Edge

IE11, the landlord does not use IE6, but there should not be too many discrepancies

Safari, the main author is the Windows system Safari version is relatively low

Sogou browser, once the landlord is also infatuated with it for a while!

The QQ browser (version) is quite powerful. Now, in addition to the most popular Chrome browsers, dual-core Trident and Blink, the main website is very fast under the Chrome kernel.

360 security browser compatibility mode, using the Trident kernel of IE

Firefox, not much to mention. Netscape is a genuine version and a necessary browser for developers.

Chrome. Currently, Google is the most popular browser.

360 secure browser speed mode, Chrome kernel, fast

Code Result Analysis

PS: javascript method for obtaining browser addresses and Parameters

Use javascript to obtain url Information

Run the following javascript code to obtain url Information:

  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 introduction to the window. location Method for obtaining URLs

The complete URL of the unified Resource Locator (Uniform Resource Locator, URL) consists of the following parts:

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

Scheme: Communication Protocol

Common http, ftp, maito, etc.

Host: host

The host name or IP address of the server (Computer) Domain Name System (DNS.

Port: port Number

INTEGER (optional) Default port used when the scheme is omitted. For example, the default port of http is 80.

Path: path

A string separated by zero or multiple "/" symbols. It is generally used to represent a directory or file address on the host.

Query: query

Optional. Used for dynamic web pages (such as CGI, ISAPI, PHP/JSP/ASP. NET and other technologies) Transfer Parameters. Multiple parameters can be separated by the "&" symbol. The names and values of each parameter are separated by the "=" symbol.

Fragment: Information fragment

String used to specify fragments in network resources. For example, if a webpage contains multiple glossary, you can use fragment to directly locate the glossary. (Also called anchor .)

Example:

1, window. location. href

The whole URl string (the complete address bar in the browser)

Returned value: http: // www. Dw. Cn: 80/index. asp? Id = 209 # asp

2, window. location. protocol

URL protocol section

Returned value: http:

3, window. location. host

Host part of the URL,

Return Value: www. Dw. Cn

4, window. location. port

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

Returned value in this example: NULL

5, window. location. pathname

URL path (that is, the file address)

Returned value:/index. asp

6. window. location. search

Query (parameter) section. In addition to assigning values to dynamic languages, we can also assign values to static pages and use javascript to obtain expected parameter values.

Returned value :? Id = 209

7. window. location. hash

Anchor

Returned value: # asp

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.