confirm msg on onUnload?

  • Thread starter Nithya Venkatachalam
  • Start date
N

Nithya Venkatachalam

Hi,

Is there anyway to display a confirm msg onUnload of a page?

I mean to say if iam calling onUnload=javascript:check();

and in check(){

if(confirm("check?"))
{
unload the page;
}
else
{
Dont unload , just come back to the previous state( i have some
values in text fields to be retained)
}
}

I want to call this function on Unload.
Suggest me a way.
 
M

Martin Honnen

Nithya said:
Is there anyway to display a confirm msg onUnload of a page?

I mean to say if iam calling onUnload=javascript:check();

and in check(){

if(confirm("check?"))
{
unload the page;
}
else
{
Dont unload , just come back to the previous state( i have some
values in text fields to be retained)
}
}

I want to call this function on Unload.

You should set
event.returnValue = 'Check?'
e.g.
<body onunload="event.returnValue = 'Check?';">
that is all that is allowed, then your message will appear in the same
confirmation dialog the default confirmation message is in.
 
M

Michael Winter

On 30 Aug 2004 06:22:00 -0700, Nithya Venkatachalam <[email protected]>
wrote:

I'm assuming this is for the Web. If you're actually writing something for
a more restricted environment where you know precisely what browsers will
be used, say so. The advice might change.
Is there anyway to display a confirm msg onUnload of a page?

The practical answer is no. Whilst you *might* be able to display a
message or perform some action, you certainly can't prevent the browser
from closing[1]. The only reliable approach is to ensure you cater for a
user leaving abnormally (setting automatic session timeouts on the server,
etc.).

Moreover, any script approach can be disabled or skipped by a user.
I mean to say if iam calling onUnload=javascript:check();

<body ... onunload="check()">

[snip]

Mike


[1] Granted, IE allows cancellation using onbeforeunload, but not everyone
uses IE.
 
M

Martin Honnen

Martin said:
You should set
event.returnValue = 'Check?'
e.g.
<body onunload="event.returnValue = 'Check?';">

That should be
<body onbeforeunload="event.returnValue = 'Check?';">
 

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,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top