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

Javascript浏览器对象模型(BOM)

2009-06-03 10:21 761 查看
Javascript浏览器对象模型(BOM)

CSSER整理,如有疑问请联系。

BOM指(Brower Object Model)浏览器对象模型。

window对象的属性:

document frames history location navigator screen

document对象的属性:

anchors forms images links location

window对象

观察BOM的体系结构,所有的对象都源自window对象,它表示整个浏览器窗口。

Frame实际是个array,如果窗口分祯的话,每个frame相当一个单独的window对象,如window.frames[0](注意,top对象的使用,top永远指向最外层的祯,top.frames[0], 因为当你的代码被包括在某个frame中是,这时候window指向的是当前祯,这也许不是你的原意,所以尽量使用top来避免错误)

parent ,self,top,window的关系:

parent:如果当前窗口为frame,指向包含该frame的窗口的frame (frame)

self :指向当前的window对象,与window同意。 (window对象)

top :如果当前窗口为frame,指向包含该frame的top-level的window对象

window :指向当前的window对象,与self同意。

window的有用属性/对象与方法

大小与移动:

moveBy,moveTo,resizeBy,resizeTo;

打开popup窗口:

open;

系统提示窗:

alert(),confirm(),prompt;

状态栏:

Status,defaultStatus;

时间间隔:

setTimeout(),setInterval;

历史纪录:

history.go(-1)后退

document对象

唯一BOM和DOM都有的对象。从BOM的角度看,侧重于从集合的角度看问题,把页面划分为不同的部分,以及页面本身的一些属性,如背景色,标题名称等,由于BOM的实现是基于浏览器的,所以不同浏览器的属性和方法有不一致之处,这造成很多麻烦。注意一些一致的,常用的属性和方法,BOM把页面分为如下几部分:

anchors : Collection of all anchors in the page(represented by <a name="anchorname"></a>)

applets : Collection of all applets in the page

forms : Collection od all embeded objects in the page(represented by the <embed /> tag)

images : Collection of all forms in the page

links : Collection of all links in the page (represented by <a href="somewhere.htm"></a>)

location 对象

指浏览器窗口中输入的URL,它有很多属性,即把URL拆为了很多部分,分别表示之,如href,host,port,pathname等

Navigator对象

更加针对浏览器,举一些IMOS都有的例子如appCodeName,appName, userAgent等

Screen对象

这个Screen指的是客户计算机的屏幕,如我的机器的Screen.Heigh和Width为768X1024,例如可以用这个属性将浏览器置为全屏:

window.moveTo(0, 0);

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