1、設置或獲取整個URL 為字符串:
window.location.href
2、設置或獲取與URL 關聯的端口號碼:
window.location.port
3、設置或獲取URL 的協議部分
window.location.protocol
4、設置或獲取href 屬性中跟在問號後面的部分
window.location.search
5、獲取變量的值(截取等號後面的部分)
複製代碼代碼如下:
var url = window.location.search;
// alert(url.length);
// alert(url.lastIndexOf('='));
var loc = 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