当前路径还有file://
<script>
alert(window.location.pathname)
</script>
当前路径
<script>
alert(window.location.href);<wbr><br>
</script><br><br>
设置或获取与 URL 关联的端口号码。<br>
<script><br>
alert(window.location.port)<br>
</script></wbr>
设置或获取 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>
本文详细介绍了JavaScript中window.location对象的各种属性,包括pathname、href、port、protocol、hash、host及search等,展示了如何通过这些属性来操作和获取当前网页的URL信息。

被折叠的 条评论
为什么被折叠?



