BOM 瀏覽器對象模型
1、Borwser Object Model ? ? ? ?
2、 用來描述瀏覽器相關信息的幾個對象 ? ? ??
3、其中代表瀏覽器窗口的window對象是BOM的頂層對象,其他對象都是該對象的子對象庆杜。
BOM
1、Window 整個窗口(頂層)
2碟摆、Location url信息
3晃财、History 歷史記錄
4、Screen 屏幕相關
5典蜕、Navigator 瀏覽器版本及客戶機信息
Window 概述
1断盛、window是客戶端JavaScript的全局對象
2、它表示web瀏覽器的一個窗口或窗體愉舔,并且用標識符window來引用
? ? ? ? 是所有客戶端javascript特性和API的主要接入點
? ? ? ? Window包含? location history screen navigator? document
1. window
? ? ? ?1钢猛、 innerHeight 返回窗口的文檔顯示區(qū)高度 IE9以下不兼容
? ? ? ?2、innerWidth 返回窗口的文檔顯示區(qū)寬度 IE9以下不兼容
? ? 解決方法
? ? ? ? document.write('視口的寬 : '+document.documentElement.offsetWidth+"
");
? ? ? ? document.write('視口的高 : '+document.documentElement.clientHeight+"
");
? ? ? ? 3轩缤、outerWidth 返回窗口外部寬度 IE9以下不兼容
? ? ? ? 4命迈、outerHeigh 返回窗口外部高度 IE9以下不兼容
? ? 解決方法? --暫無
? ? ? ? 5.彈窗 alert() 無返回值 confirm() 有返回值 prompt() 有返回值
? ? ? ? 6.setInterval() clearInterval()
? ? ? ? 7.setTimeout() clearTimeout()
? ? ? ? 8.print() window.print();
? ? ? ? 9.scrollTo(x,y) 將內(nèi)容滾動到指定坐標
? ? ? ? 10.scrollBy() 按照指定像素滾動 ---回到頂部
? ? ? ? 11.moveTo(x,y) window.moveTo()僅IE
? ? ? ? 12.moveBy() window.moveBy()僅IE
? ? ? ? 13.resizeTo() 將窗口大小調(diào)整到指定的寬度和高度 僅IE
? ? ? ? 14.resizeBy() 按照指定像素調(diào)整窗口大小 僅IE
2. location
? ? ? ? 表示該窗口中當前顯示的文檔的URL 并定義了方法來使窗口載入新的文檔
? ? ? ? 屬性
? ? ? ? 1贩绕、href 設置或返回當前的URL協(xié)議
? ? ? ? 2、protocol 設置或返回當前URL的協(xié)議
? ? ? ? 3躺翻、host 設置或返回主機名和當前URL的端口號
? ? ? ? 4丧叽、hostname 設置或返回當前URL的主機名
? ? ? ? 5卫玖、port 設置或返回當前URL的端口號
? ? ? ? 6公你、pathname 設置或返回當前URL的路徑部分
? ? ? ? 7、hash 設置或返回從#開始的錨
? ? ? ? 8假瞬、search 設置或返回從陕靠?開始的URL查詢部分
? ? ? ? document.write(location+'
');
? ? ? ? ? ? ? ? document.write('href : '+location.href+'
');
? ? ? ? ? ? ? ? document.write('protocol(協(xié)議) : '+location.protocol+'
');
? ? ? ? ? ? ? ? document.write('host(主機名和端口號) : '+location.host+'
');
? ? ? ? ? ? ? ? document.write('hostname(主機名) : '+location.hostname+'
');
? ? ? ? ? ? ? ?document.write('port(端口號) : '+location.port+'
');
? ? ? ? --虛擬端口
? ? ? ? --物理端口
? ? ? ? ? ? ? ?document.write('pathname(路徑信息) : '+location.pathname+'
');
? ? ? ? ? ? ? ?document.write('search(查詢信息) : '+location.search+'
');
? ? ? ? ? ? ? ?document.write('hash(錨點) : '+location.hash+'
');
? ? ? ?方法
? ? ? ?1、reload(); --重新加載當前文檔 location.reload();
? ? ? ? 2脱茉、assign(); --加載新的文檔 ? ? ? ? location.assign(“http://www.baidu.com”);
? ? ? ?3剪芥、replace(); --替換當前文檔 location.replace(“http://www.baidu.com”);
? ? ? ?--自定義一個超鏈接
? ? ? ?--定時刷新
三、navigator
該對象描述了瀏覽器廠商和版本信息 (瀏覽器相關信息)
1琴许、Navigator 是為了紀念NetSpace公司的Navigator 瀏覽器
2税肪、appName 返回瀏覽器的名稱 --只讀
3、cookieEnabled 返回一個布爾值榜田。true (cookie)可用益兄。false 被禁用。
4箭券、appVersion 返回瀏覽器的平臺和版本信息
5净捅、userAgent 返回由客戶機發(fā)送服務器user-agent頭部的值
6、platform 返回運行瀏覽器的操作系統(tǒng)平臺
7辩块、onLine 是否在線
四蛔六、history
1、back() 加載history列表中的前一個URL.
2废亭、forward() 加載history列表中下一個URL
3国章、go() 加載history列表中的某個具體頁面 (有參數(shù))
五、screen
概述:提供有關窗口顯示大小和可用顏色數(shù)量的信息
1豆村、width 返回顯示器屏幕的寬度
2液兽、height 返回顯示器屏幕的高度
3、availWidth 返回顯示屏幕寬度(除windows任務欄之外)
4你画、availHeight 返回顯示屏幕高度(出windows任務欄之外)
5抵碟、colorDepth 返回目標設備或緩沖器上的調(diào)色板的比特深度