alert pop-up box when closing the browser window

Discussion in 'ASP .Net' started by buran, Dec 29, 2004.

  1. buran

    buran Guest

    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
     
    buran, Dec 29, 2004
    #1
    1. Advertising

  2. 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<

    "buran" <> wrote in message
    news:...
    > 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
    >
    >
     
    Dimitri Glazkov, Dec 29, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Vk1J?=

    Closing popup window when closing parent window?

    =?Utf-8?B?Vk1J?=, Feb 14, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    679
    Thomas Hansen
    Feb 15, 2007
  2. Ganesh
    Replies:
    0
    Views:
    585
    Ganesh
    Jun 29, 2007
  3. point

    closing window and alert problem...

    point, Jul 12, 2003, in forum: Javascript
    Replies:
    0
    Views:
    109
    point
    Jul 12, 2003
  4. cruster
    Replies:
    0
    Views:
    87
    cruster
    Mar 22, 2006
  5. optimistx

    Alert box and pop up blockers?

    optimistx, Oct 5, 2009, in forum: Javascript
    Replies:
    4
    Views:
    134
    Thomas 'PointedEars' Lahn
    Oct 7, 2009
Loading...

Share This Page