JS中通过window.open弹出的窗口,我们可以通过窗口对象的close方法来关闭,下面的代码演示了通过两个按钮分别打开和关闭窗口的方法
<!DOCTYPE html> <html> <head> <script> function openWin() { myWindow=window.open("","","width=200,height=100"); myWindow.document.write("<p>This is 'myWindow'</p>"); } function closeWin() { myWindow.close(); } </script> </head> <body> <input type="button" value="Open 'myWindow'" onclick="openWin()" /> <input type="button" value="Close 'myWindow'" onclick="closeWin()" /> </body> </html>