location對(duì)象
location物件表示目前頁(yè)面的URL資訊。例如,一個(gè)完整的URL:
http://www.example.com:8080/path/index.html?a=1&b=2#TOP
可以用location.href取得。要取得URL各部分的值,可以這麼寫(xiě):
location.protocol; // 'http' location.host; // 'www.example.com' location.port; // '8080' location.pathname; // '/path/index.html' location.search; // '?a=1&b=2' location.hash; // 'TOP'
要載入一個(gè)新頁(yè)面,可以呼叫l(wèi)ocation.assign()。如果要重新載入目前頁(yè)面,呼叫l(wèi)ocation.reload()方法非常方便。
location 物件屬性:
location 物件方法: