In JavaScript, you can close the window through the close() method; for example, directly use "window.close();" to close the current window, or you can use "
.close() ;" to close the specified window.
The operating environment of this tutorial: Windows 7 system, ECMAScript version 5, Dell G3 computer.
JavaScript-Close window (window.close)
The close() method is used to close the browser window.
Usage:
window.close(); //关闭本窗口
or
<窗口对象>.close(); //关闭指定的窗口
Description
Method close() will close the top-level browser window specified by window. A window can close itself by calling self.close() or just close().
Only windows opened by JavaScript code can be closed by JavaScript code. This prevents malicious scripts from terminating the user's browser.
Example:
<script type="text/javascript"> var mywin=window.open('//m.sbmmt.com'); //将新打的窗口对象,存储在变量mywin中 mywin.close(); </script>
For more programming-related knowledge, please visit: Programming Video! !
The above is the detailed content of How to close window in javascript. For more information, please follow other related articles on the PHP Chinese website!