1,設置或獲取對象指定的文件名或路徑。
console.log(window.location.pathname)
2,設置或獲取整個 URL 為字符串。
console.log(window.location.href);
3,設置或獲取與 URL 關聯的端口號碼。
console.log(window.location.port)
4,設置或獲取 URL 的協議部分。
console.log(window.location.protocol)
5,設置或獲取 href 屬性中在井號“#”后面的分段。
console.log(window.location.hash)
6,設置或獲取 location 或 URL 的 hostname 和 port 號碼。
console.log(window.location.host)
1
7,設置或獲取 href 屬性中跟在問號后面的部分。
console.log(window.location.search)
8,獲取變量的值(截取等號后面的部分)
var url = window.location.search;
9,用來得到當前網頁的域名
var domain = document.domain;
function getRootPath() {
//獲取當前網址,
var curPath = window.document.location.href;
//獲取主機地址之后的目錄,
var pathName = window.document.location.pathname;
var pos = curPath.indexOf(pathName);
//獲取主機地址
var localhostPaht = curPath.substring(0, pos);
//獲取帶"/"的項目名,
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
return (localhostPaht);
}