JS获取当前页面页面URL信息

来源:互联网 发布:中国运输服务贸易数据 编辑:程序博客网 时间:2024/05/17 07:38
URL即:统一资源定位符 (Uniform Resource Locator, URL)
完整的URL由这几个部分构成:
scheme://host:port/path?query#fragment
scheme:通信协议
常用的http,ftp,maito等

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

url = http://www.baidu.com/baidu/postedit/46887983?wd=hei+jude&tn=monline_4_dg

window.location.pathname;  

--->  "/baidu/postedit/46887983"

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

url = http://www.baidu.com/baidu?wd=hei+jude&tn=monline_4_dg

window.location.href; 

--->  "http://www.baidu.com/baidu?wd=hei+jude&tn=monline_4_dg"


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

url =http://192.168.14.97:2000/analytics/profiles/

window.location.port;

--->  "2000"

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

url = http://www.baidu.com/baidu?wd=hei+jude&tn=monline_4_dg

window.location.protocol;

--->  "http:"

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

url = http://192.168.2.11/forum.php?mod=viewthread&tid=65&page=1&extra=#pid207

window.location.hash; 

--->  "#pid207"

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

url = http://192.168.14.97:2000/analytics/profiles/

window.location.host; 

--->  "192.168.14.97:2000"

 

设置或获取 location 或 URL 的 hostname。

url = http://192.168.14.97:2000/analytics/profiles/

window.location.hostname;  

--->  "192.168.14.97"


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

url = http://www.baidu.com/baidu?wd=hei+jude&tn=monline_4_dg

window.location.search;  ---> 

 "?wd=hei+jude&tn=monline_4_dg"

 

获取变量的值(截取等号后面的部分)

    var url = window.location.search;
    var loc = url.substring(url.lastIndexOf('=')+1, url.length);

0 0
原创粉丝点击