Location接口表示它链接到的对象的位置(URL)。所做的修改反映在与其相关的对象上。Document和Window接口都有这样一个链接的Location,分别通过Document.location和Window.location访问。Location对象属性散列设置或返回从井号(#)开始的URL(锚点)。假设当前的URL是:http://example.com:1234/test.htm#part2,那么console.log(location.hash)输出“#part2”主机设置或者返回当前的主机名和端口号网址。假设当前URL是:http://example.com:1234/test.htm#part2然后console.log(location.host)输出“example.com:1234”主机名设置或返回当前URL的主机名。假设当前URL是:http://example.com:1234/test.htm#part2,那么console.log(location.hostname)输出“example.com”。hrefhref属性是一个可读可写的字符串。它可以设置或返回当前显示文档的完整URL。假设当前的URL是:http://example.com:1234/test.htm#part2那么console.log(location.href)输出"http://example.com:1234/test.htm#part2"pathname的pathname属性是一个可读可写的字符串,可以设置或返回当前URL的路径部分。假设当前的URL是:http://example.com:1234/test/test.htm#part2,那么console.log(location.pathname)输出“/test.test.html”。portport属性是一个可读的可写字符串,用于设置或返回当前URL的端口部分。假设当前的URL是:http://example.com:1234/test.htm#part2,那么console.log(location.port)输出“1234”。protocol属性是一个可读可写的字符串,可以设置或返回当前URL的协议。假设当前的URL是:http://example.com:1234/test.htm#part2,那么console.log(location.protocol)的输出就是“http:”提示:如果输入的端口号有误,输出值为chrome-errorsearchsearch属性是一个可读写的字符串,可以设置或返回当前URL的查询部分(问号后面的部分?)假设当前URL为:http://www.w3school.com.cn/ti..然后console.log(location.search)输出"?f=hdom_loc_search"Location对象方法assign()加载新文档reload()重新加载当前文档replace()替换当前文档window.location与一个新文件。assign(url):加载由URL指定的新HTML文档。相当于一个链接,跳转到指定的url,当前页面会转换为新页面的内容,点击可以返回上一页。window.location.replace(url):通过加载URL指定的文档来替换当前文档。该方法是替换当前窗口页面。前后两个页面共享同一个窗口,因此无法返回上一页。即:replace()方法不会在History对象中生成新记录。使用此方法时,新的URL将覆盖History对象中的当前记录。刷新页面的几种方式1history.go(0)2location.reload()3location=location4location.assign(location)5document.execCommand('Refresh')6window.navigate(location)7location.replace(位置)8document.URL=location.href
