File size: 2,393 Bytes
08aee07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Window对象</title>

    </head>
    <body>
        <input id="openBtn" type="button" value="打开窗口">
        <input id="closeBtn" type="button" value="关闭窗口">

        <script>
            /*
            BOM:
	            1. 概念:Browser Object Model 浏览器对象模型
	            	* 将浏览器的各个组成部分封装成对象。

	            2. 组成:
	            	* Window:窗口对象
	            	* Navigator:浏览器对象
	            	* Screen:显示器屏幕对象
	            	* History:历史记录对象
	            	* Location:地址栏对象
	        */

	        /*
	        1、特点:
	          * Window对象不需要创建可以直接使用 window使用。 window.方法名();
	          * window引用可以省略。  方法名();
            */
	        alert("Hello");
	        window.alert("Hello");


	        /*
	        2、与弹出框有关的方法:
	            alert()	显示带有一段消息和一个确认按钮的警告框。
	            confirm()	显示带有一段消息以及确认按钮和取消按钮的对话框。
	                * 如果用户点击确定按钮,则方法返回true
	                * 如果用户点击取消按钮,则方法返回false
	            prompt()	显示可提示用户输入的对话框。
	                * 返回值:获取用户输入的值
	        */
	        var flag = confirm("您确定要退出吗?");
            alert(flag);

            var result = prompt("请输入密码");//输入框
            alert(result);


            /*
            3、与打开关闭有关的方法:
	           close()	关闭浏览器窗口。
	               * 谁调用我 ,我关谁
	           open()	打开一个新的浏览器窗口
	               * 返回新的Window对象
            */
            //打开一个新窗口
            var openBtn = document.getElementById("openBtn");
            var newWindow;
            openBtn.onclick = function() {
                newWindow = open("http://www.baidu.com");
            }

            //关闭一个新窗口
             var closeBtn = document.getElementById("closeBtn");
            closeBtn.onclick = function() {
                newWindow.close();
            }

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