JavaScript Tutorial: Getting the current address bar URL

Source: Internet
Author: User
Tags query resource window domain name port number

URL is: Uniform Resource Locator (uniform Resource Locator, URL)
The complete URL is composed of these parts:
Scheme://host:port/path?query#fragment
Scheme: Communication protocol
Common Http,ftp,maito Host: mainframe
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.) For such a URL http://www.x2y2.com:80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere
We can use JavaScript to get every part of it.
1, Window.location.href
Entire URL string (in the browser is the complete address bar)
This example returns a value of: Http://www.x2y2.com:80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere 2, Window.location.protocol
The protocol part of the URL
This example returns a value of: Http:3,window.location.host
Host part of URL
This example returns a value of: www.x2y2.com 4,window.location.port
Port portion of URL
If the default 80 port (update: Even if added: 80), then the return value is not the default of 80 but null characters
This example returns a value of: "" 5,window.location.pathname
The path portion of the URL (that is, the file address)
This example returns a value of:/fisker/post/0703/window.location.html 6,window.location.search
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
This example returns a value:? ver=1.0&id=6 7,window.location.hash
Anchor Point
This example returns a value: #imhere

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.