当前路径还有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>
本文详细解析了JavaScript中用于定位网站路径与URL关键属性的方法,包括当前路径、完整URL、端口号、协议、哈希标记、主机名、搜索参数及host属性等,帮助开发者更好地理解并运用这些技术。
1396

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



