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