Home > Web Front-end > JS Tutorial > body text

How to close window in javascript

青灯夜游
Release: 2023-01-04 09:33:53
Original
10802 people have browsed it

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.

How to close window in javascript

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();   //关闭本窗口
Copy after login

or

<窗口对象>.close();   //关闭指定的窗口
Copy after login

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(&#39;//m.sbmmt.com&#39;); //将新打的窗口对象,存储在变量mywin中
   mywin.close();
</script>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template