JS operation URL (window. Location)

Source: Internet
Author: User
Window. Location

 

One thing I tested myself:

========================================================== ============================

<HTML>

<Body>

 

<SCRIPT type = "text/JavaScript">

VaR selflocation = Window. Location. href. Split ('? ');

VaR Feng = selflocation [1]. Split ('= ')

Document. Write (FENG [1]);

</SCRIPT>

 

</Body>

</Html>

 

Http://www.w3school.com.cn/htmldom/prop_loc_href.asp

========================================================== ========

Window. Location Method to get URL

Uniform Resource Locator (Uniform Resource Locator, URL)

The complete 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 to produce web pages) transmission parameters, can have multiple parameters, separated by the "&" symbol, each parameter name and value 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:

Http://www.home.com: 8080/Windows/location/page.html? Ver = 1.0 & id = timlq # Love

1, window. Location. href

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

Returned value: http://www.home.com: 8080/Windows/location/page.html? Ver = 1.0 & id = timlq # Love 2, window. Location. Protocol

URL protocol section

Returned value: http:

3, window. Location. Host

Host part of the URL,

Returned value: www.home.com

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: 8080

5, window. Location. pathname

URL path (that is, the file address)

Returned value:/Windows/location/page.html

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 :? Ver = 1.0 & id = timlq

7. Window. Location. Hash

Anchor

Returned value: # Love

Supplementary content For such a URL Http://www.x2y2.com: 80/Fisker/post/0703/rows configurlocation.html? Ver = 1.0 & id = 6 # imhere

We can use JavaScript to obtain all the parts.
1,Window. Location. href
The whole URL string (the complete address bar in the browser)
Returned value in this example: http://www.x2y2.com: 80/Fisker/post/0703/optional parameter location.html? Ver = 1.0 & id = 6 # imhere

2,Window. Location. Protocol
URL protocol section
Returned value in this example: http:

3,Window. Location. Host
Host part of the URL
Return Value in this example: www.x2y2.com

4,Window. Location. Port
URL Port
If the default port 80 is used (Update: Even if: 80 is added), Then the returned value is not the default 80, but an empty character.
Returned value in this example :""

5,Window. Location. pathname
URL path (that is, the file address)
Returned value in this example:/Fisker/post/0703/window.location.html

6,Window. Location. Search
Query (parameter)
In addition to assigning values to dynamic languages, we can also assign values to static pages and use JavaScript to obtainLetterParameter Value
Return Value in this example :? Ver = 1.0 & id = 6

7,Window. Location. Hash
Anchor
Returned value in this example: # imherehttp: // www.x2y2.com: 80/Fisker/post/0703/window.location.html? Ver = 1.0 & id = 6 # imhere

We can use JavaScript to obtain all the parts.
1,Window. Location. href
The whole URL string (the complete address bar in the browser)
Returned value in this example: http://www.x2y2.com: 80/Fisker/post/0703/optional parameter location.html? Ver = 1.0 & id = 6 # imhere

2,Window. Location. Protocol
URL protocol section
Returned value in this example: http:

3,Window. Location. Host
Host part of the URL
Return Value in this example: www.x2y2.com

4,Window. Location. Port
URL Port
If the default port 80 is used (Update: Even if: 80 is added), Then the returned value is not the default 80, but an empty character.
Returned value in this example :""

5,Window. Location. pathname
URL path (that is, the file address)
Returned value in this example:/Fisker/post/0703/window.location.html

6,Window. Location. Search
Query (parameter)
In addition to assigning values to dynamic languages, we can also assign values to static pages and use JavaScript to obtainLetterParameter Value
Return Value in this example :? Ver = 1.0 & id = 6

7,Window. Location. Hash
Anchor
Returned value in this example: # imhere

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.