location
window.location 和 document.location 等价
改变location.href会重新定位到一个URL,而修改location.hash会跳到当前页面中的anchor(<a id="name">或者<div id="id">等)名字的标记(如果有),而且页面不会被重新加载
通过location.search可以获得url中从第一个?开始到第一个#之前的内容
通过location.hash可以获得url中从第一个#开始之后的所有内容
因此如果在?之前存在#,则location.search为空。
例如:
URL:http://b.a.com:88/index.php?name=kang&how=#when=2016#first
- search
"?name=kang&how=" - hash
"#when=2016#first"
通过接口跳转回原页面时页面未重新加载问题
部分浏览器中,当通过接口跳转时,如hash以外部分未改变则页面不会重新加载,此时可以通过加一个中间页面做跳转