如何用JS得到当前页面的URL信息

如何用JS得到当前页面的URL信息,第1张

设置或获取对象指定的文件名或路径。

<script>

alert(windowlocationpathname)

</script>

设置或获取整个 URL 为字符串。

<script>

alert(windowlocationhref);

</script>

设置或获取与 URL 关联的端口号码。

<script>

alert(windowlocationport)

</script>

设置或获取 URL 的协议部分。

<script>

alert(windowlocationprotocol)

</script>

设置或获取 href 属性中在井号“#”后面的分段。

<script>

alert(windowlocationhash)

</script>

设置或获取 location 或 URL 的 hostname 和 port 号码。

<script>

alert(windowlocationhost)

</script>

设置或获取 href 属性中跟在问号后面的部分。

<script>

alert(windowlocationsearch)

</script>

获取项目根目录

在jsp里去<%=requestgetContextPath()%>这就是项目的根路径了,是到项目这层的。

js的引入方法如下:

<script src="<%=requestgetContextPath() %> /home/testjs"></script>

css的引入方法:

<link href="<%=requestgetContextPath() %>/css/onecss" rel="stylesheet" type="text/css">

以上就是关于如何用JS得到当前页面的URL信息全部的内容,包括:如何用JS得到当前页面的URL信息、如何让引用的js文件获取本项目根路径、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9605436.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存