Window.location method can also take parameters such as Href,search, let us look at the URL to get the parameters of the method.
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.
Http://localhost/test/test.htm?id=1
Code to copy code as follows
<body>
<script languge=javascript>
alert (window.location.pathname); --Return to/test/test.htm
alert (Window.location.search); --return? id=1
alert (WINDOW.LOCATION.HREF); --Return to Http://localhost/test/test.htm?id=1
</script>
</body>
The Location object contains information about the current URL. The entire URL string for the property href.
Protocol A string that contains the first part of the URL, such as http:
Host contains a string with the hostname: Port number part of the URL. As//www.cenpok.net/server/
Hostname A string that contains the host name in the URL. such as http://www.cenpok.net;
Port contains a string of port numbers that may exist in the URL.
Pathname the "/" section of the URL. such as ~list/index.htm
The string after the hash "#" (CGI argument).
Search "?" String after the number (CGI parameter).
For such a URL
Code to copy code as follows
Http://www.php230.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
The entire URL string (in the browser is the full address bar)
This example returns a value:
Code to copy code as follows
Http://www.php230.com:80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere
2,window.location.protocol
The protocol portion of the URL
This example returns the value: http:
3,window.location.host
The host part of the URL
This example returns the value: Www.php230.com
4,window.location.port
The port portion of the URL
If you are using the default 80 port (update: Even if you added: 80), the return value is not the default of 80 but the null character
This example returns the value: ""
5,window.location.pathname
The path portion of the URL (that is, the file address)
This example returns the value:/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 values of the arguments we believe in.
This example returns the value:? ver=1.0&id=6
7,window.location.hash
Anchor Point
This example returns the value: #imhere
[js]window.location get URL details of each parameter