2020.04.06 BOM中的Window对象

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Window对象</title>

</head>
<body>
<input type="button" value="打开窗口" id="button">
<input type="button" value="关闭已经打开的那个窗口" id="closeW">
<script>
/*
Window:窗口对象
1.创建
2.方法
1.与弹出框有关的方法
alert():显示带有一段消息和一个确认按钮的警告框
confirm():显示带有一段消息以及确认按钮和取消按钮的对话框。
如果点击确认则返回true 如果点击取消则返回false
prompt():显示可提示用户输入的对话框。
返回值为输入的值
2.与打开关闭有关的方法:
open():打开一个新的浏览器窗口
返回一个新的window对象
close():关闭浏览器窗口
谁调用关谁
3.属性
4.特点
*window对象不需要创建可以直接使用window来使用 window.方法名()
*window可以省略 方法名();
*/
/* alert("Hello window");
window.alert("Hello aojie");*/

/* var flag=confirm("您确定要退出吗?");
if (flag){
document.write("<img src='img/banner_3.jpg'>");
}*/

//输入框
/* var result=prompt("请输入用户名:");
alert(result);*/

var openWindow=document.getElementById("button");
var newWindow;
var closeWindow=document.getElementById("closeW");
openWindow.onclick=function () {
newWindow=open("http://www.baidu.com");
}
closeWindow.onclick=function () {
newWindow.close();
}

</script>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/aojie/p/12649828.html