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

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

window.location.href

获取内容:http://10.100.0.8:7000/SVP/

"window.location.href" "http://10.30.60.187:7000/PPIS/templates/WfrmMain_Test.html"

备注:设置页面跳转,可更改此值

 

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

window.location.port:7000

设置或获取 URL 的协议部分 

window.location.protocol

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

window.location.search

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

复制代码 代码如下:

var url = window.location.search;

// alert(url.length);

// alert(url.lastIndexOf('='));

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

 

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

window.location.hash

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

window.location.host

获取内容:10.100.0.8:7000

window.location.hostname

获取内容:10.100.0.8

获取当前用户访问的ip地址以及城市地区

前提:需要联网

引用下面的js:

<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>

直接获取IP和城市名:

 alert(returnCitySN['cip'] + returnCitySN['cname']);

其他

"document.domain" "10.30.60.187"

个人随笔,如有错误,敬请指正

原文地址:https://www.cnblogs.com/7q4w1e/p/9549468.html