JavaScript Window基础整理 - 1

1  Window对象

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

全局变量是window对象的属性,全局函数是window的对象方法。

2 获取Window尺寸

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

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

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

对于 Internet Explorer 8、7、6、5:

document.documentElement.clientHeight

document.documentElement.clientWidth

或者

document.body.clientHeight

document.body.clientWidth

实用的 JavaScript 方案(涵盖所有浏览器):

3 其他Window方法

window.open() - 打开新窗口

window.close() - 关闭当前窗口

window.moveTo() - 移动当前窗口

window.resizeTo() - 调整当前窗口的尺寸

4 Window.Screen对象包含有关用户屏幕的信息

screen.availWidth - 可用的屏幕宽度

screen.availHeight - 可用的屏幕高度

5 Window.location 对象用于获得当前页面的地址(URL),并把浏览器重新定向到新的页面

一些例子:

location.hostname 返回 web 主机的域名

location.pathname 返回当前页面URL的路径和文件名

location.port 返回 web 主机的端口 (80 或 443)

location.protocol 返回所使用的 web 协议(http:// 或https://)

location.href 属性返回当前页面的 URL。

location.assign() 方法加载新的文档。

你可能感兴趣的:(JavaScript Window基础整理 - 1)