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
Commonly used Http,ftp,maito, etc.
Http://localhost/test/test.htm?id=1
code is as follows |
copy code |
<body> <script languge=javascript> Alert ( Window.location.pathname); --return /test/test.htm Alert (window.location.search); -Returns 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. Property href the entire URL string.
Protocol A string containing the first part of the URL, such as http:
The host contains a string with the host name: part of the port number in the URL. such as//www.cenpok.net/server/
Hostname A string containing 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 after the "/" in the URL. such as ~list/index.htm
The string after the hash "#" (the CGI parameter).
Search "?" String after the number (CGI parameter).
For such a URL
The code is as follows |
Copy Code |
Http://www.111cn.net: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:
The code is as follows |
Copy Code |
Http://www.111cn.net: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 the value: http:
3,window.location.host
Host part of URL
This example returns a value of: www.111cn.net
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 the value: ""
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