如何用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>

通过js可以获取

function getQueryString(name) {

var reg = new RegExp("(^|&)" + name + "=([^&])(&|$)", "i");

var r = windowlocationsearchsubstr(1)match(reg);

if (r != null) return unescape(r[2]); return null;

}

//这样调用:

alert(GetQueryString("参数名1"));

alert(GetQueryString("参数名2"));

alert(GetQueryString("参数名3"));

当一个url过来时,如:>

代码如下:

<% String basepath 

=requestgetScheme()+"://"+requestgetServerName()+":"+requestgetServerPort() ;

String Path = requestgetScheme()+"://"+requestgetServerName()+":"+requestgetServerPort()+path+"/"+requestgetContextPath()+"/"; 

String uri=requestgetRequestURI();   

uri=urisubstring(urilastIndexOf("/")+1);  //获得是最后的hellojsp 

%>

(上例中,Path路径就是图中的)

说明:

1requestgetContextPath()  返回站点的根目录,如:‘’/demo‘’

2requestgetRealpath("/")得到的是实际的物理路径,也就是你的项目所在服务器中的路径

3requestgetScheme() 等到的是协议名称,默认是>

4requestgetServerName() 得到的是在服务器的配置文件中配置的服务器名称 比如:localhost baiducom 等等

5requestgetServerPort() 得到的是服务器的配置文件中配置的端口号 比如 8080等等

OK,满意的话请好评!O(∩_∩)O~

以上就是关于如何用JS得到当前页面的URL信息全部的内容,包括:如何用JS得到当前页面的URL信息、html页面的url怎样被获取、jsp怎么获取当前页面的url等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址:https://www.54852.com/web/9532518.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存