any alternate for OnBeforeUnload?

S

sowencheung

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!
 
J

Jim Ley

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

sowencheung

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?
 
J

Jim Ley

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.
 

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

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top