BOM 瀏覽器對象模型
BOM (瀏覽器對象模型),它提供了與瀏覽器窗口進行交互的對象前端
1、window對象web
Window對 象表示整個瀏覽器窗口。
1.系統消息框 alert()瀏覽器
alert('hello world!');
2.確認對話框 confirm() 函數
該方法返回一個boolean值,若是點擊ok返回true,點擊cancel返false;工具
if(confirm("肯定要刪除嗎?")){ //刪除 }
3.輸入對話框 prompt()ui
若是點擊ok將文本框中的值做爲函數值返回,若是點擊cancel返回nullspa
//若是用戶不輸入任何值或點擊取消,那麼腳本會一直彈出對話框
function requiredPrompt() { while(true) { var name = prompt("ssss"); if(name != null && name != "") { console.log(name); break; } } }
4. 打開新窗口 window.open()操作系統
window.open("http://www.baidu.com","_blank","width=300, height=200");
5.定時器setInterva() 、 setTimeout() code
定時器能夠說是js前端最經常使用的工具,幾乎全部的逐漸變化的動態效果都會使用到定時器,好比 說圖片滾動,漸隱漸現,拖拽等等.定時器分兩種分別是settimeout和setinterval. 對象
window.setInterval(); //設置循環定時器 var T = window.setInterval(test,1000); // test:執行的代碼串或函數 設置1000毫秒 window.clearInterval(); //清除循環定時器 window.clearInterval(T); window.setTimeout(); //設置單次定時器 var T = setTimeout(test,1000); // test:執行的代碼串或函數 設置1000毫秒 window.clearTimeout() // 清除單次定時器 clearTimeout();
2、history對象
history對象是window對象的子對象,對應於瀏覽器的 歷史記錄。
window.history.go(-1);//跳轉前一個頁面 window.history.go(1);//跳轉下一個頁面 history.back();//跳轉前一個頁面 history.forward();//跳轉下一個頁面
3、Location對象
Location對象也是window對象的子對象,經過它能夠獲取或設置瀏覽器的當前地址。
1.跳轉到其它頁面
window.location.href = "http://www.163.com";
location.href = "http://www.163.com";
2.從新載入頁面(刷新)
location.reload();
4、navigator對象
Navigator對象包含着有關web瀏覽器的信息,它也是window的屬性,能夠用 window.navigator 引用它,也能夠用navigator引用
例:獲取瀏覽器內部代號,名稱,操做系統等信息
var info = navigator.userAgent; alert(info);
效果圖以下