JS获取当前URL信息
- 获取当前域名:
1 2 3 4 5 6 7
| var domain = document.domain;
var domain = window.location.host;
|
- 获取当前
Url
的4种方法:1 2 3 4 5 6
| var url = window.location.href; var url = self.location.href; var url = document.URL; var url = document.location;
|
- 获取当前相对路径:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| function GetUrlRelativePath() { var url = document.location.toString(); var arrUrl = url.split("//");
var start = arrUrl[1].indexOf("/"); var relUrl = arrUrl[1].substring(start);
if(relUrl.indexOf("?") != -1){ relUrl = relUrl.split("?")[0]; } return relUrl; }
|
- 获取当前
Url
的参数1 2 3 4 5 6 7 8 9 10 11 12 13
| function GetUrlPara(){ var url = document.location.toString(); var arrUrl = url.split("?");
var para = arrUrl[1]; return para; }
|
- 获取指定
Url
参数的方法1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| function GetUrlParam(paraName) { var url = document.location.toString(); var arrObj = url.split("?");
if (arrObj.length > 1) { var arrPara = arrObj[1].split("&"); var arr;
for (var i = 0; i < arrPara.length; i++) { arr = arrPara[i].split("=");
if (arr != null && arr[0] == paraName) { return arr[1]; } } return "";
} else { return ""; } }
|
最后更新时间: