zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js获取当前页面的url网址信息

JS 获取 信息 页面 当前 url 网址
2023-06-13 09:15:28 时间
1、设置或获取整个URL为字符串:

window.location.href

2、设置或获取与URL关联的端口号码:

window.location.port

3、设置或获取URL的协议部分

window.location.protocol

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

window.location.search

5、获取变量的值(截取等号后面的部分)
复制代码代码如下:

varurl=window.location.search;
//alert(url.length);
//alert(url.lastIndexOf("="));
varloc=url.substring(url.lastIndexOf("=")+1,url.length);

6、设置或获取URL的协议部分:

window.location.protocol

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

window.location.hash

8、设置或获取location或URL的hostname和port号码:

window.location.host