天天看點

面試題:什麼是 Bom? Bom 是浏覽器對象。有哪些常用的 Bom 屬性呢?

 (1)location 對象

location.href-- 傳回或設定目前文檔的 URL location.search -- 傳回 URL 中的查詢字元串部分。例 如 http://www.dreamdu.com/dreamdu.php?id=5&name=dreamdu 傳回包括(?)後面的内 容?id=5&name=dreamdu

location.hash -- 傳回 URL#後面的内容,如果沒有#,傳回空

location.host -- 傳回 URL 中的域名部分,例如 www.dreamdu.com location.hostname -- 傳回 URL 中的主域名部分,例如 dreamdu.com

location.pathname -- 傳回 URL 的域名後的部分。例如 http://www.dreamdu.com/xhtml/ 返 回/xhtml/

location.port -- 傳回 URL 中的端口部分。例如 http://www.dreamdu.com:8080/xhtml/ 傳回 8080 location.protocol -- 傳回 URL 中的協定部分。例如 http://www.dreamdu.com:8080/xhtml/ 返 回(//)前面的内容 http:

location.assign -- 設定目前文檔的 URL 。

location.replace() -- 設定目前文檔的 URL,并且在 history 對象的位址清單中移除這個 URL location.replace(url);

location.reload() -- 重載目前頁面

(2)history 對象

history.go() -- 前進或後退指定的頁面數

history.go(num);

history.back() -- 後退一頁

history.forward() -- 前進一頁

(3)Navigator 對象

navigator.userAgent -- 傳回使用者代理頭的字元串表示(就是包括浏覽器版本資訊等的字 符串) navigator.cookieEnabled -- 傳回浏覽器是否支援(啟用)cookie

繼續閱讀