window.close的关闭窗口提示用法详解
发布时间:01/15 来源: 浏览:
关键词:
window.close在js中使用就是关闭窗口没其它的用法,下面我来简单介绍window.close()关闭窗口的一些使用技巧,大家可参考。
使用window.close来关闭由打开的窗口时,会弹出一个提示窗口,而使用window.open()打开的窗口则不会。可是使用
window.open(“about:blank”,”_self”).close()
回避这个问题。
同理,
代码如下 | |
window.parent.close() 和 window.top.close() 可以写成 window.open(“about:blank”,”_parent”).close() window.open(“about:blank”,”_top”).close() |
这样来回避这个问题。
要在程序中消除这个提示框也很简单,不过在IE6和IE7稍有不同
1. IE6
代码如下 | |
<html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>IE6Close</title> <script type="text/javascript"> function closeWin() { window.opener=null; window.close(); } </script> </head> <body> <form id="form2" runat="server"> <div> <input id="btnClose" type="button" value="close" onclick="closeWin()"/> </div> </form> </body> </html> |
2.IE7
代码如下 | |
<html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>IE7Colse</title> <script type="text/javascript"> function closeWin() { window.open('','_self',''); window.close(); } </script> </head> <body> <form id="form2" runat="server"> <div> <input id="btnClose" type="button" value="close" onclick="closeWin()"/> </div> </form> </body> </html> |