By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,701 Members | 1,782 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,701 IT Pros & Developers. It's quick & easy.

confirm msg on onUnload?

P: n/a
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.

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a


Nithya Venkatachalam wrote:
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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

P: n/a
On 30 Aug 2004 06:22:00 -0700, Nithya Venkatachalam <vn*****@gmail.com>
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.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3

P: n/a


Martin Honnen wrote:


Nithya Venkatachalam wrote:
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 should be
<body onbeforeunload="event.returnValue = 'Check?';">
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.