Often use window.location, its structure always can't remember, simple comb under, convenient later query.
Example
Url:http://b.a.com:88/index.php?name=kang&when=2011#first
| Properties |
meaning |
value |
| Protocol |
Agreement |
"http:" |
| Hostname |
The name of the server |
"B.a.com" |
| Port |
Port |
"88" |
| Pathname |
The part of the URL that is behind the host name |
"/index.php" |
| Search |
"?" The later part, also called 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 mutually equivalent and can be exchanged for use
The 8 properties of the location are both readable and writable, but only the href and hash write make sense. For example, changing the location.href will relocate to a URL, while modifying Location.hash will jump to the anchor (<a id= "name" > or <div id= "id" > etc.) name tag (if any) in the current page ), 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 one "?" After |
| Hash |
"#when =2011#first" |
The content after the first "#" |
Method
-
Location.assign (URL)
-
Location.assign (' http://www.baidu.com '); The equivalent of window.location = ' http://www.baidu.com ' means that the new address is placed in the browser history stack, meaning that the back button can still go back to the page after going to the new page.
-
Location.replace (URL)
-
As with the Assign method, this page is removed from the browser history stack, meaning that the back button cannot return to the page after jumping 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. The force is true when overloaded from the server side; False is overloaded from the browser cache, and the default value is False.
Location object for JavaScript