location

location对象表示当前页面的URL信息。例如,一个完整的URL:html

http://www.example.com:8080/path/index.html?a=1&b=2#TOP

能够用location.href获取。要得到URL各个部分的值,能够这么写:ide

location.protocol; // 'http'
location.host; // '
 location.port; // '8080'
 location.pathname; // '/path/index.html'
 location.search; // '?a=1&b=2'
 location.hash; // 'TOP'

要加载一个新页面,能够调用location.assign()。若是要从新加载当前页面,调用location.reload()方法很是方便。
spa

<a onclick="location.assign('http://www.baidu.com');">加载一个新页面</a>
<a onclick="location.reload();">从新加载当前页面</a>
相关文章
相关标签/搜索