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

方法一、正则表达式

function getQueryString(name) {

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

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

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

return null;

}

方法二、

<Script language="javascript">

function GetRequest() {

var url = locationsearch; //获取url中""符后的字串

var theRequest = new Object();

if (urlindexOf("") != -1) {

var str = urlsubstr(1);

strs = strsplit("&");

for(var i = 0; i < strslength; i ++) {

theRequest[strs[i]split("=")[0]]=unescape(strs[i]split("=")[1]);

}

}

return theRequest;

}

</script>

方法三、

/

获取指定的URL参数值

URL:>

在WEB开发中,时常会用到javascript来获取当前页面的url网址信息,在这里是我的一些获取url信息的小总结。

下面我们举例一个URL,然后获得它的各个组成部分:>

以上就是关于如何用JS得到当前页面的URL信息全部的内容,包括:如何用JS得到当前页面的URL信息、js如何获取请求中的url以及参数、前端使用js如何准确获取当前页面url网址信息等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存