BOM對象
全稱:browserobject model(瀏覽器對象模型)
bom瀏覽器對象:
window
navigator
screen
history
location
document
1.window對象
屬性:
frames//窗口數組,在谷歌中已被淘汰
opener//打開我的那個窗口
top//頂級窗口
方法:
alert();
confirm();
prompt();
setInterval();
clearInterval();
setTimeout();
clearTimeout();
(1)open
<input type="button" value="打開窗口" onclick=window.open('http://www.baidu.com')>
document.write先清空,然後再寫
//打開一個新的空白頁
var oNewWin=window.open('about:blank','_blank');
//向新頁面中寫入
oNewWin.document.write(oTxt.value);
(2)close火狐中只有用腳本開的才能用腳本關閉
2.Navigator屬性
userAgent更精確的版本
nu = navigator.userAgent; ntype = nu.match(/chrome|firefox|trident/i);//取出的是數組 switch(ntype[0].toLowerCase()){ case 'chrome': break; case 'firefox': break; case 'trident': break; }
3.screen屏幕對象
sw=screen.width;獲取屏幕寬度
sh=screen.height;獲取屏幕高度
sw=screen.availWidth;獲取有效寬度
sh=screen.availHeight;獲取有效高度
作用:獲取屏幕分辨率在通過修改link.href的樣式
4.history對象
方法:
history.back() 後退一個歷史
history.forward() 前進一個歷史
history.go(-1) 前進一個歷史
5.location地址欄
屬性
location.hash 獲取地址欄中的錨點#...
location.host 獲取地址欄的主機名(域名)
location.href 獲取地址欄地址;
location=location.href這裏是指兩者輸出內容是相同的
location.pathname 獲取url中的路徑的部分
location.protocol 獲取url中的訪問協議
location.search 獲取url中的參數部分
方法:
location.reload() 重新加載url,即是刷新