屬性名 | 例子 | 說明 |
---|---|---|
hash | "#contents" | 返回URL中的hash(#號後跟零或多個字符),若是URL中不包含散列,則返回空字符串 |
host | "www.wrox.com:80" | 返回服務器的名稱和端口號(若是有) |
hostname | "www.wrox.com" | 返回不帶端口號的服務器名稱 |
href | "http://www.wrox.com" | 返回當前加載頁面的完整URL.而location對象的toString()方法也會返回這個值 |
pathname | "/WileyCDA/" | 返回URL中的目錄和(或)文件名 |
port | "8080" | 返回URL中指定的端口號.若是URL中不包含端口號,則這個屬性返回空字符串 |
protocol | "http:" | 返回頁面使用的協議.一般是http:或https: |
search | "?q=javascript" | 返回URL的查詢字符串.這個字符串以問號開頭 |
location.assign("http://www.wrox.com");
window.location = "http://www.wrox.com";
location.href = "http://www.wrox.com"
;另外,修改location對象的其餘屬性也能夠改變當前加載的頁面(hash除外)javascript