This article transferred from: http://blog.csdn.net/chendi1985/article/details/5291773
Window.location method 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: Hosts
The server (computer) domain Name System (DNS) hostname or IP address.
Port: Port number
An integer, optionally, that omits the default port for using the scenario, such as HTTP, with the default port of 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 use with dynamic Web pages such as CGI, ISAPI, php/jsp/asp/asp. NET and other technical Web pages) pass parameters, can have multiple parameters, separated by the "&" symbol, the name and value of each parameter is separated by the "=" symbol.
Fragment: Pieces of information
String that specifies the fragment in the network resource. For example, there are multiple noun interpretations in a Web page, and you can use fragment to navigate directly to a noun interpretation. (also known as anchor points.)
Example:
Http://www.home.com:8080/windows/location/page.html?ver=1.0&id=timlq#love
1, Window.location.href
The entire URL string (in the browser is the full address bar)
return value: Http://www.home.com:8080/windows/location/page.html?ver=1.0&id=timlq#love 2,window.location.protocol
The protocol portion of the URL
Return value: http:
3,window.location.host
The host part of the URL,
return value: www.home.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: 8080
5,window.location.pathname
The path portion of the URL (that is, the file address)
return value:/windows/location/page.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.
Return value:? ver=1.0&id=timlq
7,window.location.hash
Anchor Point
return value: #love
Window.location.assign (URL) and replace (URL) differences
Window.location.assign (URL): loads The new HTML document specified by the URL . the equivalent of a link to jump to the specified URL, the current page will be converted to new page content, you can click Back to return to the previous page.
Window.location.replace (URL): Replaces the current document by loading The document specified by the URL, This method replaces the current window page, and the front and back two pages share a window, so there is no back return to the previous page
[Go]window.location method get URL and window.location.assign (URL) and replace (URL) difference