Often use window.location, its structure always remember, simple sort, to facilitate future inquiries.
Examples
URL:http://b.a.com:88/index.php?name=kang&when=2011#first
Attributes | meaning | value |
---|---|---|
protocol: | protocol | "http:" |
hostname: | Name server | "b.a.com" |
port: | port | "88" |
pathname: | Part of the URL after the hostname | "/index.php" |
search: | "?" After the section, also known as the query string | "?name=kang&when=2011" |
hash: | Content returns "#" after | "#first" |
host: | Equal hostname + port | "b.a.com:88" |
href: | The full URL of the current page | "http://www.a.com:88/index.php?name=kang&when=2011#first" |
and each window.location document.location equivalent, can be used interchangeably
location of the eight attributes are read and write, but only makes sense to write a href and hash. Such as changing location.href will be relocated to a URL, modify location.hash will jump to anchor on the current page (<a id="name"> or <div id = "id"> etc.) tag names (if there are), and the page will not be reloaded
note
URL:http://b.a.com:88/index.php?name=kang&how=#when=2011#first
search: | "?name=kang&how=" | After the first "?" |
hash: | "#when=2011#first" | After the contents of the first "#" |
method
- location.assign( url )
-
location.assign ( 'http://www.baidu.com'); equivalent to window.location = 'http://www.baidu.com'
in this way speaks a new address into the browser history stack, means go to the new page after the "back button" is still to return to the page. - location.replace( url )
- And assign the same method, but will remove this page from the browser history stack, that is to say after the jump to a new page "back button" can not return to the page. Currently IE, Chrome simply jump, Firefox will only delete the history of this page.
- location.reload( force )
- Reload the current page. Overload is true force from the server; to false from the browser cache reload, the default value of false.
Reproduced in: https: //www.cnblogs.com/rainman/archive/2011/02/20/1959054.html