標籤:
瀏覽器 window 對象(BOM)是瀏覽器宿主對象,和 js 語言無關。
【window 對象的方法】
window.alert(message);window.confirm(message);window.prompt(message[,defaultstr]);window.close(); 關閉視窗window.print(); 列印window.setIntval(運算式,毫秒)window.clearIntval(定時器對象)window.setTimeout(運算式,毫秒)window.clearTimeout(定時器對象)
【window 對象的子物件】
▲navigator 瀏覽器資訊對象 △appCodeName 內部代碼 △appName 瀏覽器名稱 △appVersion 瀏覽器版本 △platform 作業系統類型 △userAgent 使用者代理程式資訊 △cookieEnabled 是否支援 cookie▲ location 地址欄對象 △host 主機 △port 連接埠 △href 地址 △pathname 路徑 △protocol 協議 △search 查詢字串 △assign(url) 頁面跳轉▲ history 記錄 △length 記錄的數目 △back(); △foeward(); △ go();▲ screen 螢幕對象 △height 高度 △width 寬度 △availHeight 可用高度 △availWidth 可用寬度 △colorDepth 顏色▲ document HTML 文檔對象即 HTML 程式碼形成的對象,可動態改變頁面的內容
【例】navigator 對象
<script>console.log(window.navigator);</script>
輸出:
【例】location 對象
<script>console.log(window.location);</script>
輸出:
search 代表參數,例如 ?id=3
跳轉:
window.location.href = ‘*******.html‘
【例】document 對象(DOM 對象,window 對象的子物件)
<script>console.log(window.document);</script>
輸出:
Javascript 筆記與總結(2-5)window 對象