• 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>
  • 相关阅读:
    重载的概念和体现形式
    构造方法的概述和使用
    可变长参数
    成员方法的定义
    Point类的定义
    Person类的定义
    类和对象以及引用的定义
    高数学习----微积分
    高数学习----向量代数和空间解析几何
    一个无法解析的外部命令and无法解析的外部符号
  • 原文地址:https://www.cnblogs.com/Strong-stone/p/10302138.html
Copyright © 2020-2023  润新知