Bom对象模型

本文详细介绍了BOM(浏览器对象模型)中的核心组件——window对象,包括其属性、方法如alert、confirm、prompt、open等。同时,讲解了定时器的使用,如setTimeout和setInterval,以及location对象、history对象的功能,如页面重载、历史记录跳转。此外,还提及了document对象的重要属性,如links、anchors、images、location和forms。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. window对象

window对象有6大属性document, frames, history, location, navigator, screen

window.alert();

alert();   //可以不加window

result = window.confirm("yes or no?");  //有返回值

input = window.prompt("please input an number.", 0);  //返回输入的值

window.print  //打印模块

window.find  //调出查找模块


open("http://www.baidu.com") ,  //新建新页面代码www.baidu.com

open("http://www.baidu.com", "baidu")   //给新建页面命名,下次还打开相同页面

open("http://www.baidu.com", "_blank")   //打开新页面

open("http://www.baidu.com", "_parent")  //在本窗口打开页面


box = open("http://www.baidu.com");   //open返回window对象

box.alert('ok?');  //子窗口弹出提示框


window.opener  //代表父窗口


window.screenLeft, window.screenTop //有的浏览器使用window.screenX, window.screenY

window.innerWidth/window.inner.Height   //页面窗口大小

window.outerWidth/window.outerHeight   //页面窗口大小+窗口边框


跨浏览获取可是范围的页面窗口

var width = window.innerWidth;

var height = window.innerHeight;

if (typeof width != "number") {

if (document.compatMode == "css1Compat") {

width = document.documentElement.clientWidth;

height = document.documentElement.clientHeight;

} else {

width = document.body.width;

height = document.body.height;

}

}


moveTo(100, 100);   //移动窗口到(100, 100)

moveBy(10, 10);  //移动(10, 10)

resizeTo(300, 300)   //调整窗口大小为(300, 300)

resizeBy(20, 20) //调整窗口大小(20, 20)

2. 定时器

var box = setTimeout("alert('Lee');", 2000)   //2秒后执行,返回timer id

clearTimeout(box);   //disable timer


var box = setInterval("alert('Lee')", 1000)   //每1秒执行一次

clearInterval(box)  //disable interval

3. location对象

window.location   //代表当前地址

location.hash //代表当前锚点, 赋值引起页面跳转

location.port //代表端口号

location.search  //?后面的query string

location.href  // 当前页面url

location.reload()  //重新加载页面,可能从缓存中加载

location.reload(true) //不从缓存中加载

location.replace("http://www.baidu.com")  //不产生history记录

4. history对象

history.length   //历史记录个数

history.back()   //向后跳转

history.forward()  //向前跳转

history.go(num)   //向前或向后跳转num页

5. document对象

document对象有5大属性links, anchors, image, location,forms



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值