浏览器对象模型

浏览器对象模型(BOM)使JavaScript有能力与浏览器对话。

浏览器对象模型(BOM)

浏览器对象模型(Browser Object Model)尚无正式标准。

由于现代浏览器(几乎)已经实现了JavaScript交互性方面的相同方法和属性,因此常被认为是BOM的方法和属性。

window对象

所有浏览器都支持window对象。他表示浏览器窗口。

所有JavaScript全局对象、函数以及变量均自动成为window对象的成员。

全局变量是window对象的属性。

全局变量是window对象的方法。

甚至HTML DOM的document也是window对象属性之一:

window.document.getElementById("header");

与此相同:

document.getElementById("header");

window尺寸

有三种方法能够确定浏览器窗口的尺寸(浏览器的视口,不包括工具栏和滚动条)。

对于Internet Explorer、Chrome、Firefox、Opera以及Safari;

window.innerHeight-浏览器窗口的内部高度

window.innerWidth-浏览器窗口的内部高度

对于Internet Explorer8、7、6、5:

document.documentElement.clientHeight

document.documentElement.clientWidth

或者

document.body.clientHeight

document.body.clientWidth

使用的Javascript方案(涵盖所有浏览器);

实例

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();-关闭当前窗口
window.moveTo();-移动当前窗口(可以做窗口抖动)
window.resizeTo();-调整当前窗口尺寸
原文地址:https://www.cnblogs.com/Strong-stone/p/9706923.html