获取页面URL地址的js脚本

    文章来源:万象互联 更新时间:2011-11-3 20:55:54
分享:
摘要:有的时候我们需要获取当前页面的地址的一些详细信息,比如文件名路径、端口号、域名、协议等详细的页面信息。这些东西我们可以使用Javascript脚本来实现这些功能

设置或获取对象指定的文件名或路径。
    <script>
    alert(window.location.pathname)
    </script>
    设置或获取整个 URL 为字符串。
    <script>
    alert(window.location.href);
    </script>
    设置或获取与 URL 关联的端口号码。
    <script>
    alert(window.location.port)
    </script>
    设置或获取 URL 的协议部分。
    <script>
    alert(window.location.protocol)
    </script>
    设置或获取 href 属性中在井号“#”后面的分段。
    <script>
    alert(window.location.hash)
    </script>
    设置或获取 location 或 URL 的 hostname 和 port 号码。
    <script>
    alert(window.location.host)
    </script>
    设置或获取 href 属性中跟在问号后面的部分。
    <script>
    alert(window.location.search)
    </script>
版权说明:本站原创文章,由万象互联SEO优化发表.
本文地址:https://www.hulian.top/zixun/post/4520.html
在线咨询
  • 在线时间
  • 8:00-21:00