BOM简介
BOM是浏览器对象模型。
仅是 JavaScript实现的一部份,没有相关标准。
BOM 能做什么?
操作浏览器窗口
提供导航对象
提供定位对象
提供跟屏幕相关对象
BOM是浏览器对象模型。
仅是 JavaScript实现的一部份,没有相关标准。
BOM 能做什么?
操作浏览器窗口
提供导航对象
提供定位对象
提供跟屏幕相关对象
提供对cookie的支持
BOM体系结构
window对象
打开浏览器后马上创建window对象,代表整个窗口。
window对象的作用:
操作窗口
导航和打开新窗口
系统对话框
状态栏
时间间隔和暂停
历史
1.操作窗口
moveBy(dx,dy) : 移动指定的距离
moveTo(x,y) : 移动到指定位置
resizeBy(dx,dy) : 修改窗口的高宽
resizeTo(x,y) : 修改高宽为指定值
[IE]screenLeft,screenTop : 取得窗口距屏幕位置
[Mozila]screenX/screenY : 窗口位置
[Mozila]innerWidth/innerHeight : 客户区高宽
[Mozila]outerWidth/outerHeight : 窗口高宽
2.在新窗口打开链接
//parm1:要打开的url
//parm2: 子窗口名字
//parm3:left,top,width,height,toolbar,resizeable,status,location...见p64
//返回新窗口的window对象
window.open("url","新窗口名字","新窗口特性");
//关闭窗口,如果是主窗口会有提示
window.close();
//子窗口中可以取得父窗口对象,利用这个对象,可进行父子窗口传值。
top.opener
提示:新窗口可能被栏截
3.系统对话框
window.alert("字符串");
window.confirm("选择是或否");
是返回true,否返回false
window.prompt("提示信息","默认值");
OK返回输入的字符串,取消返回null
对话框的样式不可更改
对话框是模式窗口
4.状态栏
window.defaultStatus = "默认在状态栏显示内容"
window.status = "状态栏内容";
注意:不要过度使用状态栏。
5.时间间隔和暂停
var id=window.setTimeout("执行代码",毫秒数);
window.clearTimeout(id)
var id=window.setInterval("执行代码",毫秒数);
window.clearInterval(id);
6.访问历史页面
window.history.go(-1);
参数是返回的页面数,正数为前进
window.history.back();
后退
window.history.forward();
前进
window.history.length;
返回历史页面的个数
document对象
document代表窗口的空白区域。
document是window的属性
DOM和BOM均定义了doucment。
document的属性
lastModified : 页面的最后修改日期
referrer : 浏览历史中的前一个URL
title : 标题栏
URL : 当前页面的URL。
document的集合属性
anchors : 页面中所有锚点的集合
applets : 页面中所有applet的集合
embeds : 页面中所有嵌入式对象集合(<embed/>)
forms : 表单集合
images : 图片集合。
document.images[0]
document.images["imageName"]
links : 超链接集合
document的方法
write("")
writeln("");
在使用这两个方法时,要注意整个页面的元素会重新设置,所以不要轻易使用
location对象
location表示载入窗口的URL
解析URL
host : URL中的主机名称
pathname : URL中主机名后的部份
prot : 端口
protocol : 协议
search : URL中问号后面的部份
跳转到新页面
location.href = "a.html"
location.assign("a.html");
location.replace(“a.html”);//没有历史信息
刷新页面location.reload(boolean);
true : 从服务器刷新
false : 本地刷新
navigator对象
保存跟浏览器相关信息
language
userAgent
onLine
screen对象
跟屏幕相关属性
availHeight : 窗口可以使用的高度
availWidth : 窗口可以使用的宽度
colorDepth : 颜色位数
height : 屏幕高度
width : 屏幕宽度
//全屏
window.moveTo(0,0);
window.resizeTo(screen.availWidth,screen.availHeight);
BOM体系结构
window对象
打开浏览器后马上创建window对象,代表整个窗口。
window对象的作用:
操作窗口
导航和打开新窗口
系统对话框
状态栏
时间间隔和暂停
历史
1.操作窗口
moveBy(dx,dy) : 移动指定的距离
moveTo(x,y) : 移动到指定位置
resizeBy(dx,dy) : 修改窗口的高宽
resizeTo(x,y) : 修改高宽为指定值
[IE]screenLeft,screenTop : 取得窗口距屏幕位置
[Mozila]screenX/screenY : 窗口位置
[Mozila]innerWidth/innerHeight : 客户区高宽
[Mozila]outerWidth/outerHeight : 窗口高宽
2.在新窗口打开链接
//parm1:要打开的url
//parm2: 子窗口名字
//parm3:left,top,width,height,toolbar,resizeable,status,location...见p64
//返回新窗口的window对象
window.open("url","新窗口名字","新窗口特性");
//关闭窗口,如果是主窗口会有提示
window.close();
//子窗口中可以取得父窗口对象,利用这个对象,可进行父子窗口传值。
top.opener
提示:新窗口可能被栏截
3.系统对话框
window.alert("字符串");
window.confirm("选择是或否");
是返回true,否返回false
window.prompt("提示信息","默认值");
OK返回输入的字符串,取消返回null
对话框的样式不可更改
对话框是模式窗口
4.状态栏
window.defaultStatus = "默认在状态栏显示内容"
window.status = "状态栏内容";
注意:不要过度使用状态栏。
5.时间间隔和暂停
var id=window.setTimeout("执行代码",毫秒数);
window.clearTimeout(id)
var id=window.setInterval("执行代码",毫秒数);
window.clearInterval(id);
6.访问历史页面
window.history.go(-1);
参数是返回的页面数,正数为前进
window.history.back();
后退
window.history.forward();
前进
window.history.length;
返回历史页面的个数
document对象
document代表窗口的空白区域。
document是window的属性
DOM和BOM均定义了doucment。
document的属性
lastModified : 页面的最后修改日期
referrer : 浏览历史中的前一个URL
title : 标题栏
URL : 当前页面的URL。
document的集合属性
anchors : 页面中所有锚点的集合
applets : 页面中所有applet的集合
embeds : 页面中所有嵌入式对象集合(<embed/>)
forms : 表单集合
images : 图片集合。
document.images[0]
document.images["imageName"]
links : 超链接集合
document的方法
write("")
writeln("");
在使用这两个方法时,要注意整个页面的元素会重新设置,所以不要轻易使用
location对象
location表示载入窗口的URL
解析URL
host : URL中的主机名称
pathname : URL中主机名后的部份
prot : 端口
protocol : 协议
search : URL中问号后面的部份
跳转到新页面
location.href = "a.html"
location.assign("a.html");
location.replace(“a.html”);//没有历史信息
刷新页面location.reload(boolean);
true : 从服务器刷新
false : 本地刷新
navigator对象
保存跟浏览器相关信息
language
userAgent
onLine
screen对象
跟屏幕相关属性
availHeight : 窗口可以使用的高度
availWidth : 窗口可以使用的宽度
colorDepth : 颜色位数
height : 屏幕高度
width : 屏幕宽度
//全屏
window.moveTo(0,0);
window.resizeTo(screen.availWidth,screen.availHeight);