常用屬性:
window // 視窗自身 window.self // 參照本視窗,等同 window window.name // 為視窗命名 window.defaultStatus // 設定狀態列資訊 window.location // URL 位址,設定它可開啟新頁面
常用方法:
window.alert("text") // 提示訊息對話框
window.confirm("text") // 確認對話框
window.prompt("text") // 要求鍵盤輸入的對話框
window.setInterval(action, time) // 每隔指定毫秒執行一次
window.clearInterval() // 清除定時器,終止循環
window.setTimeout(action, time) // 延遲指定毫秒後執行一次
window.open() // 開啟新視窗
window.close() // 關閉視窗
成員物件:window.event、window.document、window.history、window.screen、window.navigator、window.external。
history 物件:
history.length // 瀏覽過的頁面數 history.back() // 後退 history.forward()// 前進 history.go(i) // i>0 前進、i<0 後退到第 i 個頁面
screen 物件:
screen.width / screen.height // 螢幕寬高 screen.colorDepth // 色深 screen.availWidth / availHeight// 可用寬高(扣除工作列)
navigator 物件:
navigator.appName // 瀏覽器名稱 navigator.appVersion // 瀏覽器版本(含系統版本) navigator.platform // 作業系統類型,如 win32 navigator.systemLanguage// 系統語言,如 zh-cn navigator.userAgent // 使用者代理字串 navigator.onLine // 是否在線 navigator.cookieEnabled // 是否支援 cookie
屬性:
document.title // 文件標題,等同 HTML 的 <title> document.bgColor // 背景色 document.fgColor // 前景色(文字色) document.linkColor // 未點擊過的連結顏色 document.alinkColor // 作用中連結的顏色 document.vlinkColor // 已點擊過的連結顏色 document.URL // 設定 URL 以開啟另一網頁 document.cookie // 設定與讀取 cookie document.charset // 設定字元集,簡體中文為 gb2312
常用方法:
document.write() // 動態寫入內容 document.createElement(Tag) // 建立 HTML 標籤物件 document.getElementById(ID) // 取得指定 ID 的物件 document.getElementsByName(Name)// 取得指定 name 的物件 document.body.appendChild(oTag)// 附加子物件
body 子物件:
document.body.innerText // 設定 body 間的文字 document.body.innerHTML // 設定 body 間的 HTML document.body.bgColor // 背景色 document.body.background // 背景圖片 document.body.topMargin / leftMargin / rightMargin / bottomMargin // 四邊邊距
常用事件:onclick(單擊)、onmouseover(移入)、onmouseout(移出)。
location 子物件:
location.hash // # 之後的部分 location.host // 域名 + 連接埠 location.hostname // 域名 location.href // 完整 URL location.pathname // 目錄部分 location.port // 連接埠 location.protocol // 網路協定(http:) location.search // ? 之後的部分 location.reload() // 重新整理 location.replace(URL) // 以新網頁取代目前頁面
images 集合(頁面中的圖像):
document.images.length // <img> 標籤數量 document.images[0] // 第一個 <img> document.images.oImage.src // 透過 name 屬性參照並取得 src var oImage = new Image(); // 動態建立圖像物件