JavaScript window.location ObjectsExample Note method
Often use window.location, its structure is always unable to remember, simple comb, easy to query later. Sample
Url:http://b.a.com:88/index.php?name=kang&when=2011#first
Property |
meaning |
value |
Protocol |
Agreement |
"http:" |
Hostname |
Name of the server |
"B.a.com" |
Port |
Port |
"88" |
Pathname |
Part of the host name in the URL |
"/index.php" |
Search |
"?" The latter part, also known as the query string |
"? name=kang&when=2011" |
Hash |
Returns the content after "#" |
"#first" |
Host |
equals 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" |
Window.location and document.location are equivalent to each other and can be exchanged using
The 8 attributes of location are readable and writable, but only the writing of href and hash makes sense. For example, changing the location.href will reposition to a URL, and the modification Location.hash will jump to the tag (<a id= "name" > or <div id= "id" >, etc.) in the current page (if any ), and the page will not be reloaded attention
url:http://b.a.com:88/index.php?name=kang&how= #when =2011#first
Search |
"? name=kang&how=" |
The first "?" After |
Hash |
"#when =2011#first" |
The content after the first "#" |
MethodLocation.assign (URL) location.assign (' http://www.baidu.com '); equal to Window.location = ' http://www.baidu.com '
This way the new address is put into the browser history stack, meaning that the back button can still return to the page after the new page has been transferred. The Location.replace (URL) is the same as the Assign method, but deletes this page from the browser history stack, which means that the back button cannot return to the page when you jump to a new page. At present, IE, chrome is just a simple jump, only Firefox will delete the history of this page. Location.reload (force) Reload the current page. Overload from the server side when force is true, and false is overloaded from the browser cache, and the default value is False.