首页  >  文章  >  web前端  >  js获取当前页面路径示例讲解_javascript技巧

js获取当前页面路径示例讲解_javascript技巧

WBOY
WBOY原创
2016-05-16 17:04:541069浏览

设置或获取对象指定的“文件名”或路径。
<script><BR>alert(window.location.pathname)<BR></script>

设置或获取整个 URL 为字符串。
<script><BR>alert(window.location.href); <BR></script>

设置或获取与 URL 关联的端口号码。
<script><BR>alert(window.location.port)<BR></script>

设置或获取 URL 的协议部分。
<script><BR>alert(window.location.protocol)<BR></script>

设置或获取 href 属性中在井号“#”后面的分段。
<script><BR>alert(window.location.hash)<BR></script>

设置或获取 location 或 URL 的 hostname 和 port 号码。
<script><BR>alert(window.location.host)<BR></script>

设置或获取 href 属性中跟在问号后面的部分。
<script><BR>alert(window.location.search)<BR></script>

网页刷新推荐-JS







声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn