您的位置:首页 > Web前端 > JavaScript

JS获取页面当前路径的相关信息

2011-08-16 09:45 423 查看
当前路径还有file://

<script>

alert(window.location.pathname)

</script>

当前路径

<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: