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

How to close the page in javascript

藏色散人
Release: 2023-01-05 16:11:44
Original
6329 people have browsed it

Javascript method to close the page: 1. Close the window without any prompt through "window.close();"; 2. Close the page through "custom_close"; 3. Through "javascript:window.opener" =null;"Close the current page.

How to close the page in javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

JS summary of several ways to close the current page (window)

1. JS code to close the window without any prompts

The code is as follows:

关闭
Copy after login

2. Custom prompt close

The code is as follows:



Copy after login

3.Close the current page:

The code is as follows:

关闭如果是按钮则:
Response.Write("");
Copy after login

In this way, when you click close, the dialog box that the current window is trying to close will not pop up.

So how can the close button pop up when the user clicks the close button in the browser's maximize/minimize close button? What about the confirmation dialog box? Like this:

The code is as follows:

Copy after login

In this case, the onbeforeunload function will be executed when the click is closed, and a dialog box will pop up asking "Do you really want to close this window?" , click Cancel to return false, do not close, click OK to return True and close the window

So how can I pop up the OK Cancel dialog box when clicking a certain button?? If you click Cancel, the following code will not be executed. Click OK to continue executing the following code?

Write in the click of the button:

The code is as follows:

Response.Write("");
Copy after login

It means: first use the confirm function to pop up A dialog box with confirmation to cancel. If you click OK, it will return true and execute the window.location.href='default.aspx' code. If you click cancel, it will return false and execute history.back(); to return to Original page

[Recommended learning:javascript advanced tutorial

The above is the detailed content of How to close the page 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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!