location對象
location對象表示當前頁面的URL信息。例如,一個完整的URL:
http://www.example.com:8080/path/index.html?a=1&b=2#TOP
可以用location.href獲取。要獲得URL各個部分的值,可以這么寫:
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'
要加載一個新頁面,可以調(diào)用location.assign()。如果要重新加載當前頁面,調(diào)用location.reload()方法非常方便。
location 對象屬性:
location 對象方法: