alert pop-up box when closing the browser window

B

buran

Dear ASP.NET Programmers,

I am developing an intranet application using ASP.NET. I want to add such a
functionality that the application displays a pop-up box to confirm when the
user tries to close the windows using X box. I want the pop-up to be
displayed when the user clicks on the X box of the browser window (namely,
when the user closes the browser window). It's not important whether the
data is changed or not.
onbeforeunload event hook works also when I am changing the page. I only
want to display when the user closes the application window, not when he/she
browses to another page in the application. How can I accomplish this?
Thanks in advance,

Burak
 
D

Dimitri Glazkov

There is no easy way to accomplish this. From the perspective of DHTML DOM
model, closing of the browser window and going to a different page are the
same event.

However, you could probably trick the system into doing this. Here's how:

1) Define a flag that would be set to true, if the user on any of page's
links
2) Add "onclick" event handler to all anchor elements that lead to another
pages. The event handler will set the flag to true.
3) Add "onunload" event handler to window element that would check for the
flag and only display the alert box if the flag is not true.

This solution has limitations. For instance, if the user simply types a new
URL in the address bar, the flag will remain set to false, thus producing
the alert box.

Hope this helps.

:DG<
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top