OnBeforeUnload

C

crjunk

I'm working with a script that uses the OnBeforeUnload event. If the
user has made changes to a record and has not saved the record, the
script will inform the user and give them a chance to go back and save
it. From what I understand IE and FireFox 0.9 and above recognive this
event. These are the only two browser that I currently have to test
with.

What happens if the user has a browser that does not support this?
Will the script simply not run or will an error be thrown?

window.onbeforeunload = SaveChangesPrompt;
function SaveChangesPrompt() {
if ((document.ScheduleForm.txtRecordStatus.value) == "Changes Made;
Record Not Saved.")
{
return "You have attempted to leave this page without saving. Press
Ok continue WITHOUT saving or Cancel to go back and save your work.";
}
}

This script isn't necessary, but it would be nice to inform the user
that they have not saved their work.

Thanks,
CR Junk
 
L

Lee

crjunk said:
I'm working with a script that uses the OnBeforeUnload event. If the
user has made changes to a record and has not saved the record, the
script will inform the user and give them a chance to go back and save
it. From what I understand IE and FireFox 0.9 and above recognive this
event. These are the only two browser that I currently have to test
with.

What happens if the user has a browser that does not support this?
Will the script simply not run or will an error be thrown?

window.onbeforeunload = SaveChangesPrompt;
function SaveChangesPrompt() {
if ((document.ScheduleForm.txtRecordStatus.value) == "Changes Made;
Record Not Saved.")
{
return "You have attempted to leave this page without saving. Press
Ok continue WITHOUT saving or Cancel to go back and save your work.";
}
}

This script isn't necessary, but it would be nice to inform the user
that they have not saved their work.

I think you meant to return the output from a prompt() call, didn't you?

Since all you're really doing is creating a global function
named onbeforeunload(), browsers that don't call such a
function in response to an unLoad event won't be bothered.
 
M

Michael Winter

crjunk said:
[snip]
window.onbeforeunload = SaveChangesPrompt;
function SaveChangesPrompt() {
if ((document.ScheduleForm.txtRecordStatus.value) == "Changes Made;
Record Not Saved.")
{
return "You have attempted to leave this page without saving. Press
Ok continue WITHOUT saving or Cancel to go back and save your work.";
}
}
[snip]

I think you meant to return the output from a prompt() call, didn't you?

No, you return a string value. The browser does the prompting itself.

Mike
 
L

Lee

Michael Winter said:
crjunk said:
[snip]
window.onbeforeunload = SaveChangesPrompt;
function SaveChangesPrompt() {
if ((document.ScheduleForm.txtRecordStatus.value) == "Changes Made;
Record Not Saved.")
{
return "You have attempted to leave this page without saving. Press
Ok continue WITHOUT saving or Cancel to go back and save your work.";
}
}
[snip]

I think you meant to return the output from a prompt() call, didn't you?

No, you return a string value. The browser does the prompting itself.

So, you're suggesting that I should either read the documentation or
at least try a method once myself before offering advice about it?
I'll consider that. Thanks.
 
M

Michael Winter

On 13/07/2005 14:13, Lee wrote:

[snip]
So, you're suggesting that I should either read the documentation or
at least try a method once myself before offering advice about it?

Simply stating a point of fact. You aren't the only one to have assumed
that it's up to the script to provide the prompt. The beforeunload event
is anomalous in this regard.
I'll consider that. Thanks.

Was I meant to infer something from that, or am I reading your post in a
way you didn't intend?

Mike
 

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

Latest Threads

Top