1,設(shè)置或獲取對(duì)象指定的文件名或路徑。
alert(window.location.pathname)
2,設(shè)置或獲取整個(gè) URL 為字符串。
alert(window.location.href);
3,設(shè)置或獲取與 URL 關(guān)聯(lián)的端口號(hào)碼。
alert(window.location.port)
4,設(shè)置或獲取 URL 的協(xié)議部分。
alert(window.location.protocol)
5,設(shè)置或獲取 href 屬性中在井號(hào)“#”后面的分段。
alert(window.location.hash)
6,設(shè)置或獲取 location 或 URL 的 hostname 和 port 號(hào)碼。
alert(window.location.host)
7,設(shè)置或獲取 href 屬性中跟在問號(hào)后面的部分。
alert(window.location.search)
8,獲取變量的值(截取等號(hào)后面的部分)
var url = window.location.search;
// alert(url.length);
// alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length);
9,用來得到當(dāng)前網(wǎng)頁的域名
var domain = document.domain;
- url里的參數(shù)
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
}
// 調(diào)用方法
alert(GetQueryString("參數(shù)名1"));