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 |
<!DOCTYPE html> <head> <meta charset= "utf-8" > <title>window.open和window.close的使用详解</title> </head> <body> <button id= "openWindow" >打开窗口</button> <button id= "closeWindow" >关闭窗口</button> <script> ( function (){ var
$ = function (id) { return
document.getElementById(id);} var
win = null ; //打开窗口 $( ‘openWindow‘ ).onclick = function () { win = window.open(); } //关闭窗口 $( ‘closeWindow‘ ).onclick = function () { win && win.close(); } //自动关闭窗口 window.close(); })(); </script> </body> </html> |
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 |
<!DOCTYPE html> <head> <meta charset= "utf-8" > <title>window.open和window.close的使用详解</title> </head> <body> <button id= "openWindow" >打开窗口</button> <button id= "closeWindow" >关闭窗口</button> <script> ( function (){ var
$ = function (id) { return
document.getElementById(id);} var
win = null ; //打开窗口 $( ‘openWindow‘ ).onclick = function () { win = window.open( ‘about:blank‘ , ‘_blank‘ , ‘width=200,height=200‘ ); //win.opener指的是新窗口原始窗口 //alert(win.opener === window); } //关闭窗口 $( ‘closeWindow‘ ).onclick = function () { win && win.close(); //主动关闭窗口后win.opener为false //alert(win.opener === window); } //alert(window.opener === window); //自动关闭窗口 //window.close(); })(); </script> </body> </html> |
window.open和window.close的使用详解,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/xiaoheimiaoer/p/3735076.html