BOM:瀏覽器對象模型。
window 對象:它表明瀏覽器的窗口。
全部全局 JavaScript 對象,函數和變量自動成爲 window 對象的成員。
全局變量是 window 對象的屬性。document 對象也是 window 對象屬性。
全局函數是 window 對象的方法。web
窗口尺寸window.innerHeight
: 瀏覽器窗口的內高度(以像素計)window.innerWidth
: 瀏覽器窗口的內寬度(以像素計)
窗口方法window.open()
: 打開新窗口window.close()
: 關閉當前窗口window.moveTo()
: 移動當前窗口window.resizeTo()
: 從新調整當前窗口瀏覽器
window.history 對象包含瀏覽器歷史。
history.back()
: 等同於在瀏覽器點擊後退按鈕history.forward()
: 等同於在瀏覽器中點擊前進按鈕服務器
window.location 對象可用於獲取當前頁面地址(URL)並把瀏覽器重定向到新頁面。
location.href
返回當前頁面的 href (URL)location.hostname
返回 web 主機的域名location.pathname
返回當前頁面的路徑或文件名location.protocol
返回使用的 web 協議(http: 或 https:)location.assign
加載新文檔函數
window.navigator 對象包含有關訪問者的信息。
userAgent
: 返回由瀏覽器發送到服務器的用戶代理報頭(user-agent header)spa
window.screen 對象包含用戶屏幕的信息。
對話框會阻塞線程。
alert("我是一個警告框!");
let r = confirm("請按按鈕"); if (r == true) { x = "您按了確認!"; } else { x = "您按了取消!"; }
let person = prompt("請輸入您的姓名", "比爾蓋茨"); if (person != null) { document.getElementById("demo").innerHTML = "你好 " + person + "!今天過的怎麼樣?"; }
setTimeout(function, milliseconds)
在等待指定的毫秒數後執行函數。clearTimeout()
取消setTimeout設置。線程
let timeer = setTimeout(function () { console.log("123"); }, 1000); clearTimeout(timeer);
setInterval(function, milliseconds)
每隔指定的毫秒數執行代碼clearInterval()
取消setInterval()設置代理
let timer = setInterval(function () { console.log("123"); }, 1000); clearTimeout(timer);