Home >Web Front-end >JS Tutorial >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!