Home >Web Front-end >JS Tutorial >How to Close a Browser Window Without the Confirmation Prompt?

How to Close a Browser Window Without the Confirmation Prompt?

DDD
DDDOriginal
2024-10-20 15:42:02530browse

How to Close a Browser Window Without the Confirmation Prompt?

Closing a Browser Window Without the Confirmation Prompt

When you use the window.close() function, you are faced with a prompt asking for confirmation to close the window. This can be unwanted in certain situations. This article explores a solution to suppress this confirmation prompt.

Solution:

To close a browser window without receiving the confirmation prompt, use the following code:

window.open('', '_self', '');
window.close();

In this code, the first line opens an empty window with the name _self. This effectively sets the current window as the target for closing. The second line then closes the window without triggering the confirmation prompt.

The above is the detailed content of How to Close a Browser Window Without the Confirmation Prompt?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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