URL:http://127.0.0.1:8080/index.html?name=abc&age=13#public/aaa
1蔓钟、window.location.href(設(shè)置或獲取整個(gè) URL 為字符串)
var test = window.location.href;
alert(test);
返回:http://127.0.0.1:8080/index.html?name=abc&age=13#public/aaa
2耀盗、window.location.protocol(設(shè)置或獲取 URL 的協(xié)議部分)
var test = window.location.protocol;
alert(test);
返回:http:
3、window.location.host(設(shè)置或獲取 URL 的主機(jī)部分)
var test = window.location.host;
alert(test);
返回:127.0.0.1:8080
4镶殷、window.location.port(設(shè)置或獲取與 URL 關(guān)聯(lián)的端口號(hào)碼)
var test = window.location.port;
alert(test);
返回:8080
(默認(rèn)是80)
5、window.location.pathname(設(shè)置或獲取與 URL 的路徑部分(就是文件地址))
var test = window.location.pathname;
alert(test);
返回:/index.html
6、window.location.search(設(shè)置或獲取 href 屬性中跟在問號(hào)后面的部分)
var test = window.location.search;
alert(test);
返回:?name=abc&age=13
獲得查詢(參數(shù))部分熏矿,除了給動(dòng)態(tài)語言賦值以外,我們同樣可以給靜態(tài)頁面离钝,并使用javascript來獲得相信應(yīng)的參數(shù)值票编。
7、window.location.hash(設(shè)置或獲取 href 屬性中在井號(hào)“#”后面的分段)
var test = window.location.hash;
alert(test);
返回:#public/aaa