any alternate for OnBeforeUnload?

Discussion in 'Javascript' started by sowencheung@gmail.com, Jun 6, 2006.

  1. Guest

    the bug of onbeforeunload is so obvious!

    in IE 6 it will popup twice "sometimes"

    I am using the following code

    window.onbeforeunload = null;
    window.onbeforeunload = confirmExit;
    var executingPostBack = false;

    function confirmExit()
    {
    if ( typeof executingPostBack != 'undefined' && !executingPostBack)
    {
    return 'Warning: Modified data has not been saved.' ;
    }
    }

    In some cases, IE pops up it twice, for example, when we click a link
    that contains "__doPostBack", onbeforeunload is fired the first time;
    when the form is submitted, it is fired second time.

    There is no way to work it around, because onbeforeunload is stupid, we
    can't know whether the user clicks OK or Cancel.

    I would like to use the following code with confirm so that I know
    exactly what the user behaves

    res = confirm("leaving?");
    if (res==1)
    {
    alert("yes");
    }
    else
    {
    alert("no");
    }

    but I can't use this in onbeforeunload, because I can't stop it!
    onbeforeunload always asks for something return, but if I return
    anything, it will popup!

    anyway, I hope someone understands my feeling.

    is there any genius can help me out of this?
    thanks!
     
    , Jun 6, 2006
    #1
    1. Advertising

  2. Jim Ley Guest

    On 6 Jun 2006 12:08:17 -0700, wrote:

    >the bug of onbeforeunload is so obvious!
    >
    >in IE 6 it will popup twice "sometimes"
    >
    >I am using the following code
    >
    >window.onbeforeunload = null;
    >window.onbeforeunload = confirmExit;
    >var executingPostBack = false;
    >
    >function confirmExit()
    >{
    > if ( typeof executingPostBack != 'undefined' && !executingPostBack)
    > {
    > return 'Warning: Modified data has not been saved.' ;
    > }
    >}
    >
    >In some cases, IE pops up it twice, for example, when we click a link
    >that contains "__doPostBack", onbeforeunload is fired the first time;
    >when the form is submitted, it is fired second time.


    The problem is the __doPostBack, and not the onbeforeunload, or FAQ
    4.24

    Jim.
     
    Jim Ley, Jun 6, 2006
    #2
    1. Advertising

  3. Guest

    i will have to say, it is a bug of IE at least

    see

    http://dbforums.com/showthread.php?t=622842

    i agree if i change to href="#", it will work
    but it's not possible. those code are generated by .net, and our system
    is really huge, and whoever is going to use LinkButton must override
    the prerender to modify the link, is it feasible in your opinion?
     
    , Jun 6, 2006
    #3
  4. Jim Ley Guest

    On 6 Jun 2006 12:36:06 -0700, wrote:

    >i will have to say, it is a bug of IE at least


    It's absolutely not a bug in IE, if you tell the UA to navigate to
    javascript:X expect it to do it!

    >but it's not possible. those code are generated by .net, and our system
    >is really huge, and whoever is going to use LinkButton must override
    >the prerender to modify the link, is it feasible in your opinion?


    Well you really should've considered all this when picking such a poor
    quality framework, if it's incompatible, have it produce better code,
    I understand webforms can do that.

    Jim.
     
    Jim Ley, Jun 6, 2006
    #4
    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. Kathy Burke
    Replies:
    0
    Views:
    2,842
    Kathy Burke
    Aug 4, 2003
  2. Rick Lubanovic

    onbeforeunload event is fired twice

    Rick Lubanovic, Oct 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    827
    Rick Lubanovic
    Oct 30, 2003
  3. Chris
    Replies:
    2
    Views:
    700
    Chris
    Mar 4, 2007
  4. saurabh
    Replies:
    5
    Views:
    1,230
    James Kanze
    Feb 17, 2009
  5. Replies:
    10
    Views:
    340
    Sean O'Halpin
    Jul 17, 2006
Loading...

Share This Page