window對象
window對象表示當(dāng)前的瀏覽器窗口队萤。
window對象的成員屬性就是全局屬性。
window對象的成員方法就是全局方法勾扭。
全局屬性
JSON
document Document對象
console Console
screen Screen
location Location
history History
navigator Navigator
Storage
localStorage HTML5 本地存儲
sessionStorage
closed 是否關(guān)閉
parent 父窗口
self 當(dāng)前窗口自己毡琉,等價于window。
innerHeight 文檔顯示區(qū)的高度
innerWidth 寬度
outerHeight 窗口的外部高度(包含工具條和滾動條)
outerWidth 外部寬度
全局方法
三種彈出框
alert(?message) 警告框妙色。無返回值|返回值為undefined桅滋。
confirm(?message) 確認(rèn)框。返回值為boolean類型(true或false)身辨。
prompt(?message, ?defaultValue) 提示框丐谋。返回值為string類型或為null。
定時
setTimeout(handler, ?timeout, ...arguments) 設(shè)置超時時間
clearTimeout(?handle)
setInterval(handler, ?timeout, ...arguments) 設(shè)置間隔時間
clearInterval(?handle)
字符串編碼及解碼
escape(html) 對HTML代碼|漢字進行編碼(編碼為Unicode煌珊,格式:\uxxxx)
unescape(string) 對Unicode字符串進行解碼|對漢字直接返回号俐。
window.escape("你好")
"%u4F60%u597D"
window.unescape("%u4F60%u597D")
"你好"
window.unescape("你好")
"你好"
Base64編碼及解碼
btoa(asciiStr) 對傳入的英文字符串進行Base64編碼。
atob(base64Str) 對經(jīng)過Base64編碼的字符串進行解碼定庵,信息還原吏饿。
btoa("Hello World")
"SGVsbG8gV29ybGQ="
atob("SGVsbG8gV29ybGQ=")
"Hello World"
URI編碼及解碼
encodeURI(uri) 編碼URI。
decodeURI(encodedURI) 解碼經(jīng)過編碼的URI蔬浙。
encodeURIComponent(uriComponent) 對uri組件進行編碼
decodeURIComponent(encodedURIComponent) 對經(jīng)過編碼的url組件進行組件解碼猪落。
window.encodeURI("https://www.baidu.com/s?wd=張三")
"https://www.baidu.com/s?wd=%E5%BC%A0%E4%B8%89"
window.decodeURI("https://www.baidu.com/s?wd=%E5%BC%A0%E4%B8%89")
"https://www.baidu.com/s?wd=張三"
encodeURIComponent("https://www.baidu.com/s?wd=張三")
"https%3A%2F%2Fwww.baidu.com%2Fs%3Fwd%3D%E5%BC%A0%E4%B8%89"
decodeURIComponent("https%3A%2F%2Fwww.baidu.com%2Fs%3Fwd%3D%E5%BC%A0%E4%B8%89")
"https://www.baidu.com/s?wd=張三"
類型判斷
window.isBlank(str) 判斷str是否為空白(空格,回車 換行等)
window.isFinite(number) 判斷number是否為有限的(若傳入string會先自動轉(zhuǎn)換成number格式敛滋,再判斷。NaN直接返回false兴革,不是有限的數(shù)值)
window.isNaN(number) 判斷number是否不是數(shù)值绎晃。(boolean和數(shù)值都會返回false,因為他們是數(shù)值)杂曲。
類型轉(zhuǎn)換
window.parseInt(string)
window.parseFloat(string)
window.Number() 構(gòu)造方法庶艾。會對傳入的變量類型進行自動轉(zhuǎn)換。
window.String()
window.Boolean()
window.Symbol()
window.Date()
window.RegExp()
window.Array();
window.Object()
其他
window.eval(str) 對字符串中的JS表達式進行重新運算擎勘,求出運算后的內(nèi)容咱揍。
窗口相關(guān)
stop() 停止頁面載入
open(?url, ?target, ?features)
close()
resizeTo(x, y)
moveTo(x, y)