<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>BOM-浏览器对象模型-- window</title>
<script>
/*
BOM-浏览器对象模型:提供独立于内容而与浏览器窗口进行交互的对象(所有对象名称字母均小写)
window:整个BOM的核心,是顶级对象
常用子对象:document(浏览器主体部分)
history(主要用于存储历史浏览信息)
location(地址栏对象,存储网址信息)
window的方法:window对象的方法在调用时,对象名可以省略
alert():弹出提示框
confirm():弹出确认框,一般用于删除事件时
prompt():弹出输入框
close():关闭窗口
open():打开新窗口 第一个参数是要打开的窗口路径,第二个参数是对新窗口起的别名,第三个参数是对新打开的窗口的限定
setInterval:定义定时器,指定某个函数在指定时间间隔内反复执行
clearInterval:清除定时器
setTimeout():定义定时器,指定某个函数在指定时间后执行一次
clearTimeout():清除定时器
* */
function deleteInfo(){
if(confirm("您确认要删除吗?")){
console.log("删除成功");
}
}
function closeWin(){
window.close();
}
function openWin(){
window.open("demo04.html","aaa","width=500px,height=300px");/*要打开的窗口路径,对新窗口起的别名,对新打开的窗口的限定*/
}
/*//定时器
var number = 1;
function printNum(){
document.write(number);
document.write("<br />");
number++;
if(number==11){
window.clearInterval(time);
}
}
var time = window.setInterval("printNum()",1000);
*/
/*//时钟定时器
function printTime(){
var now = new Date();
console.log(now.getFullYear()+'年'+(now.getMonth()+1)+'月'+now.getDate()+'日 '+now.getHours()+':'+now.getMinutes()+':'+now.getSeconds());
}
setInterval("printTime()",1000);
*/
执行一次的定时器
function closeCurWin(){
window.close();
}
setTimeout("closeCurWin()",3000);
</script>
</head>
<body>
<div>
<button type="button" onclick="deleteInfo()" >删除</button><!--不写type默认为submit-->
</div>
<div>
<button type="button" onclick="closeWin()" >关闭窗口</button><!--不写type默认为submit-->
</div>
<div>
<button type="button" onclick="openWin()" >打开新窗口</button><!--不写type默认为submit-->
</div>
<div>
3秒钟之后窗口自动关闭
</div>
</body>
</html>
