location对象
location对象包含当前页面的URL的相关信息。location对象是window对象的一个属性,可通过window.location来访问。
1.location属性:
①hash:设置或返回从#开始的URL。
②host:设置或返回URL主机名和当前URL端口号
③hostname:设置或返回URL主机名
④href:设置或返回完整的URL
⑤pathname:设置或返回当前URL的部分路径名
⑥port:设置或返回URL的端口号
⑦protocol:设置或返回当前URL协议
⑧search:设置或者返回从问号开始的URL
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>location对象</title>
<script type="text/javascript">
for(var Property in window.location)
window.document.write(Property+":"+window.location[Property]+"<br>");
</script>
</head>
<body>
<input type="button" value="重新载入" onclick="javascript:window.location.reload();">
<input type="button" value="百度" onclick="javascript:window.location.replace('http://www.baidu.com');">
</body>
</html>
2.loction对象的方法
(1)assign()方法:加载新的文档
(2)reload()方法:重新加载新的文档
(3)replace()方法:用新的文档换当前文档