window.location 对象在编写时可不使用 window 这个前缀。 一些例子:
一些实例:
location.href 属性返回当前页面的 URL。
location.pathname 属性返回 URL 的路径名。
Window Location Href
<script>
document.write(location.href);
</script>
Window Location Pathname
<script>
document.write(location.pathname);
</script>
location.assign() 方法加载新的文档。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>芝麻教程(web3.xin)</title>
</head>
<head>
<script>
function newDoc(){
window.location.assign("http://www.web3.xin")
}
</script>
</head>
<body>
<input type="button" value="加载新文档" onclick="newDoc()">
</body>
</html>