Before Unloading I need to prompt the user if the from has changed

S

sancha

Hi,
I need to promt the user when he moves away from the page by
clicking an of the links available on the page.
I was trying to use the onbeforeunload function but it seems it is a
jScript function rather than a javascript function which means it will
not work in Mozilla.

is there anyway that the user can be prompted to stay on the page.
Another big problem is that the i want a different message than the
one shown. This is because the prompt the explorer provides is 'do you
want to navigate away from this page ?' Is there any way i can do this
???

i am working in struts therefore it becomes useless to rewrite the
url.
Please help

Thanx in advance
 
M

Martin Honnen

sancha wrote:

I need to promt the user when he moves away from the page by
clicking an of the links available on the page.
I was trying to use the onbeforeunload function but it seems it is a
jScript function rather than a javascript function which means it will
not work in Mozilla.

onbeforeunload was introduced by IE 5 I think but recent Mozilla
versions implement that too, when I have the following

window.onbeforeunload = function (evt) {
var message = 'Are you sure you want to leave?';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}

then Firefox 1.0 for instance asks for confirmation when trying to
navigate away from the page. IE 6 too.

As for JScript and JavaScript, event handlers like onbeforeunload are
part of the client-side object model and not part of the language itself:
<http://jibbering.com/faq/#FAQ2_8>
 
G

Grant Wagner

sancha said:
Hi,
I need to promt the user when he moves away from the page by
clicking an of the links available on the page.
I was trying to use the onbeforeunload function but it seems it is a
jScript function rather than a javascript function which means it will
not work in Mozilla.

Actually, onbeforeunload is an event only available in the IE DOM, it
has nothing to do with JavaScript vs JScript (which are simply two
implementations of ECMAScript).

Second, modern versions of Gecko-based browsers do understand
onbeforeunload.

Third, if someone is leaving your page, they probably want to leave your
page. Asking them if they want to leave your page after they have made a
conscious decision to leave your page seems annoying and pointless.

Fourth, using onbeforeunload, how are you determining that the user is,
in fact, navigating off your page, and not to another page on your site.
onbeforeunload has no way of knowing this, so it will make a prompt
appear for every navigation outside and within your site.
is there anyway that the user can be prompted to stay on the page.
Another big problem is that the i want a different message than the
one shown. This is because the prompt the explorer provides is 'do you
want to navigate away from this page ?' Is there any way i can do this
???

If you want to make use of onbeforeunload, you simply return a string
which will be added to the default prompt. As the documentation at <url:
http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onbeforeunload.asp
/> states:

" When a string is assigned to the returnValue property of window.event,
a dialog box appears that gives users the option to stay on the current
page and retain the string that was assigned to it. The default
statement that appears in the dialog box, "Are you sure you want to
navigate away from this page? ... Press OK to continue, or Cancel to
stay on the current page.", cannot be removed or altered."
i am working in struts therefore it becomes useless to rewrite the
url.
Please help

<body onbeforeunload="return 'I want to annoy you so I\'m forcing the
display of this prompt.';">
 
S

sancha

Hi,
It is just that i need to prompt the user when he moves off the
page to save the page. Since the message
"Are you sure you want to
navigate away from this page? ... Press OK to continue, or Cancel to
stay on the current page.", cannot be removed or altered is there any
other way that i can do this ? the only way i can think is to attach a
function to all the links on my site. This would do it but since i have
a loi of links on the page it might become a bit tedious.
is there any other way that i can get a different prompt ???

Thanx
 

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
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top