您的位置:首页 > Web前端 > JavaScript

【JavaScript】基础知识整理(四)

2016-03-30 21:44 651 查看

浏览器对象模型(BOM)

BOM使JavaScript有能力与浏览器对话

window对象

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

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

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

全局函数是window对象的方法。

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

window.document.getElementById( “header” );

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 方案(涵盖所有浏览器):

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()

Screen

window.screen 对象在编写时可以不使用 window 这个前缀。

Location

window.location 可以不使用window这个前缀

location.hostname 返回 web主机的域名

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

location.port 返回web主机的端口

location.protocol 返回使用的web协议(http:// 或 https://)
location.href属性返回当前页面的url

History

window.history 可省略 window 这个前缀

history.back()

history.forward()

Navigator

可省略window前缀

PopuAlert

Timing

cookie

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: