JS Close the current page (window) several ways to summarize

Source: Internet
Author: User

1. Close the JS code of the window without any hint

<a href="javascript:window.opener=null;window.open (', ' _self '); Window.close (); "> Close </a>

2. Custom Prompt off

<Scriptlanguage= "JavaScript">//This script is a generic script for IE6 and IE7functionCustom_close () {if(Confirm ("Are you sure you want to close this page? ") ) {Window.opener=NULL; window.open ("','_self'); Window.close ();}Else{}}</Script><inputID= "Btnclose"type= "button"value= "Close this page"OnClick= "Custom_close ()" />

3. Close the current page:

<ahref= "javascript:window.opener=null;window.close ();">Shut down</a>If the button is: Response.Write ("<Scriptlanguage=\ "Javascript\">Window.opener=NULL; Window.close ();</Script>");

This will not pop up as the current window is trying to close the dialog box.

So how about that? When the user points the browser to maximize the Minimize Close button in the Close button also pops up the closed confirmation dialog box?

<onbeforeunload= "Return" Do you really want to close this window? ' " >

So in the point of closing time will be executed onbeforeunload function, pop really to close this window of the dialog box, point cancel return false, do not close, point OK return true close window

So how to be able to click on a button to pop the OK Cancel dialog box?? If the point cancel does not execute the following code, click OK to continue executing the following code?

In the button's click, write:

Response.Write ("<Scriptlanguage=\javascript\ ">" + "if(Confirm (\"OK? \ "))"+"{window.location.href= ' default.aspx ';}"+"else{history.back ();}"+"</Script>");

This means: First use the Confirm function to pop up a dialog box with OK Cancel, if you click OK to return to true, execute window.location.href= ' default.aspx ' code, if the point is canceled return False, execute History.back () ; Return to the original page

JS Close the current page (window) several ways to summarize

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.