BOM

Window

Window 尺寸

對于Internet Explorer、Chrome、Firefox、Opera 以及 Safari:
window.innerHeight - 瀏覽器窗口的內(nèi)部高度(包括滾動條)
window.innerWidth - 瀏覽器窗口的內(nèi)部寬度(包括滾動條)
對于 Internet Explorer 8、7、6、5:
document.documentElement.clientHeight
document.documentElement.clientWidth
或者
document.body.clientHeight
document.body.clientWidth

var w=window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;

var h=window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
其他 Window 方法

window.open() - 打開新窗口
window.close() - 關(guān)閉當(dāng)前窗口
window.moveTo() - 移動當(dāng)前窗口
window.resizeTo() - 調(diào)整當(dāng)前窗口的尺寸

window.screen

screen.availWidth - 可用的屏幕寬度
screen.availHeight - 可用的屏幕高度

window. location

屬性
location.hostname 返回 web 主機(jī)的域名
location.pathname 返回當(dāng)前頁面的路徑和文件名
location.port 返回 web 主機(jī)的端口 (80 或 443)
location.protocol 返回所使用的 web 協(xié)議(http:// 或 https://)
location.href 屬性返回當(dāng)前頁面的 URL。
方法
location.assign("http://www.w3cschool.cc")

window.history

history.back() - 與在瀏覽器點(diǎn)擊后退按鈕相同
history.forward() - 與在瀏覽器中點(diǎn)擊向前按鈕相同
history.go(N);

window.navigator

txt = "<p>瀏覽器代號: " + navigator.appCodeName + "</p>";
txt+= "<p>瀏覽器名稱: " + navigator.appName + "</p>";
txt+= "<p>瀏覽器版本: " + navigator.appVersion + "</p>";
txt+= "<p>啟用Cookies: " + navigator.cookieEnabled + "</p>";
txt+= "<p>硬件平臺: " + navigator.platform + "</p>";
txt+= "<p>用戶代理: " + navigator.userAgent + "</p>";
txt+= "<p>用戶代理語言: " + navigator.systemLanguage + "</p>";

彈窗

window.alert("sometext");
window.confirm("sometext");
window.prompt() 方法可以不帶上window對象,直接使用prompt()方法。

計(jì)時器

setInterval() - 間隔指定的毫秒數(shù)不停地執(zhí)行指定的代碼。
setTimeout() - 在指定的毫秒數(shù)后執(zhí)行指定代碼。
clearInterval(intervalVariable)
clearTimeout(timeoutVariable)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容