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