CODEDIGEST
Home Articles CodeDigest Tutorials FAQs
Home > CodeDigest >  
Technologies
 


How to open a popup window when user closes the browser close button in ASP.Net?
Submitted By Satheesh Babu B
On 4/24/2010 12:30:29 AM
Tags: asp.net,CodeDigest  

How to open a popup window when user closes the browser close button in ASP.Net?

 

At times, we will have requirements to open a popup window when we close an asp.net page.

 

For example, when a user closes the browser where our site is opened we can open a popup page thanking him and getting a feedback of our site.

 

This can be achieved by opening a popup window on OnUnload event of BODY.
Refer the below code,

<script type="text/javascript">

function OpenWindow(url)
{
window.open(url);
}

</script>

<body onunload="OpenWindow('ThankYouPage.aspx')">

 

Most of the times, this may give a bad experience to user when we open a popup on closing the browser. Hence, use it only if it is required.

 

In the above code, i have just opened the popup window with no customization. You can further customize the popup window by disabling tool bars, address bars, etc. You view the Window.Open documentation in google to know more.

 

Happy Coding!!

Recent Codes
  • View All Codes..