# window 對象
[TOC]
## window對象概述
>[info] window對象是BOM的核心,window對象指當前的瀏覽器窗口所有JavaScript全局對象、函數以及變量均自動成為window對象的成員。
1.全局變量是window對象的屬性
2.全局函數是window對象的方法
甚至HTML DOM的document也是window對象的屬性之一。
## window尺寸
* window.innerWidht 瀏覽器窗口的內部寬度
* window.innerHeight 瀏覽器窗口的內部高度(不包含工具欄和滾動條的寬度)
~~~
<script>
console.log( '寬度為: ' + window.innerWidth + ',高度為: ' +window.innerHeight); // 寬度為: 1920,高度為: 406
</script>
~~~
## window方法
* window.open() 打開新窗口
* window.close() 關閉當前窗口
~~~
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Browser-obj</title>
</head>
<body>
<button id="btn">按鈕</button>
<button id="btnClose">關閉窗口按鈕</button>
<script>
function btnClick(){
/**
* 參數1 要打開的地址
* 參數2 聲明了新窗口的名稱
* 參數3 聲明了新窗口要顯示的標準瀏覽器的特征
* 窗口特征(http://www.w3school.com.cn/jsref/met_win_open.asp#windowfeatures)
*/
window.open('http://www.baidu.com','name','height=400,width=400,top=400,left=50,toolbar=yes,menubar = yes');
}
var btn = document.getElementById('btn');
btn.addEventListener('click',btnClick); // 給按鈕添加點擊事件
var btnClose = document.getElementById('btnClose');
btnClose.addEventListener('click', function(){
window.close();
}); // Chrome提示: Scripts may close only the windows that were opened by it.
</script>
</body>
</html>
~~~
- 空白目錄
- JavaScript保留字
- JS事件
- JS面向對象
- JS內置對象
- 自定義對象
- String 字符串對象
- Date 日期時間對象
- Array 數組對象
- Math 對象
- DOM對象控制HTML
- getElementsByName
- getElementsByTagName
- getAttribute 獲取元素屬性
- setAttribute 設置元素屬性
- childNodes 訪問子節點
- parentNode 訪問父節點
- createElement 創建元素節點
- createTextNode 創建文本節點
- insertBefore 插入節點
- removeChild 刪除節點
- offsetHeight 網頁高度
- scrollHeight 網頁高度
- JS瀏覽器對象
- window對象
- 計時器
- history對象
- location對象
- screen對象
- navigator對象
- 彈出窗口
- cookies