JavaScript Window Location

window.location对象用于获得当前页面地址(URL),并把浏览器重定向到新页面。

Window Location

window.location对象在编写时可不使用window这个前缀。一些例子:

    location.hostname返回web主机域名

    location.pathname返回返回当前页面的路径和文件名

    location.port返回web主机的端口(80或443)

    location.protocol返回所使用的web协议(http://或https://)

Window Location Href

location.href属性返回当前页面的URL

返回(当前页面的)整个 URL:

<script>
    document.write(location.href);
</script>

http://www.runoob.com/js/js-window-location.html

Window Location Pathname

location.pathname属性返回URL的路径名。

返回当前URL的路径名。

<script>
    document.write(location.pathname);
</script>

/js/js-window-location.html

Window Location Assign

location.assign() 方法加载新的文档。

加载一个新的文档:

<html>
<head>
<script>
function newDoc()
  {
  window.location.assign("http://www.w3cschool.cc")
  }
</script>
</head>
<body>

<input type="button" value="Load new document" onclick="newDoc()">

</body>
</html>
原文地址:https://www.cnblogs.com/Strong-stone/p/10302138.html