473,320 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

onbeforeunload issue, Mozilla Firefox

I'm assigning the onbeforeunload event a function thus (pseudo code):

window.onbeforeunload=checkForm;
function checkForm() {
if(formChanged){ return 'You changed the form, are you sure?' }
}

As a conditional unload it works fine - the prompt only appears if you
have changed form values. The issue is that Firefox/Mozilla comes up
with a warning - "function checkForm does not always return a value".

This is really annoying me - I wondered if anyone had a workaround. If
you return anything else (null, false etc.) you get the prompt.

AJP
Jul 23 '05 #1
5 14894


Alistair Potts wrote:
I'm assigning the onbeforeunload event a function thus (pseudo code):

window.onbeforeunload=checkForm;
function checkForm() {
if(formChanged){ return 'You changed the form, are you sure?' }
}

The issue is that Firefox/Mozilla comes up
with a warning - "function checkForm does not always return a value".

This is really annoying me - I wondered if anyone had a workaround. If
you return anything else (null, false etc.) you get the prompt.


The warning shouldn't annoy you, it is just an attempt to do some more
compiler like checking in a scripting language.
It should also only appear with the preference javascript.options.strict
set to true.

Even with that set to true I cannot reproduce the problem with Firefox
1.0. Which version of FF are you trying with?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
v1.0.3; you'll only see the problem with strict mode on, through a XHTML
doctype.

I appreciate it's a 'warning', but I've been careful to code without any
warnings (I get a smiley face with the web developer toolbar!).

I appreciate your feedback. Alistair

Martin Honnen wrote:


Alistair Potts wrote:
I'm assigning the onbeforeunload event a function thus (pseudo code):

window.onbeforeunload=checkForm;
function checkForm() {
if(formChanged){ return 'You changed the form, are you sure?' }
}

The issue is that Firefox/Mozilla comes up with a warning - "function
checkForm does not always return a value".

This is really annoying me - I wondered if anyone had a workaround. If
you return anything else (null, false etc.) you get the prompt.

The warning shouldn't annoy you, it is just an attempt to do some more
compiler like checking in a scripting language.
It should also only appear with the preference javascript.options.strict
set to true.

Even with that set to true I cannot reproduce the problem with Firefox
1.0. Which version of FF are you trying with?

Jul 23 '05 #3


Alistair Potts wrote:
v1.0.3; you'll only see the problem with strict mode on, through a XHTML
doctype.

I appreciate it's a 'warning', but I've been careful to code without any
warnings (I get a smiley face with the web developer toolbar!).


If you want to avoid the warning I guess you can do
if (condition) {
return 'warning message';
}
else {
return (void 0);
}
Let us know whether that avoids the warning.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
That's fantastic!

For those who don't know: "The particularity of void is, that it
evaluates the given expression, but does not return a value as a
result." So it's perfect for this situation.

AJP

Martin Honnen wrote:


Alistair Potts wrote:
v1.0.3; you'll only see the problem with strict mode on, through a
XHTML doctype.

I appreciate it's a 'warning', but I've been careful to code without
any warnings (I get a smiley face with the web developer toolbar!).

If you want to avoid the warning I guess you can do
if (condition) {
return 'warning message';
}
else {
return (void 0);
}
Let us know whether that avoids the warning.

Jul 23 '05 #5


Alistair Potts wrote:
For those who don't know: "The particularity of void is, that it
evaluates the given expression, but does not return a value as a
result." So it's perfect for this situation.


void 0 gives you the value undefined so semantically
return (void 0);
is the same as
return undefined;
which is the same as
return;
but obviously it goes unnoticed by Spidermonkey's warning generator.

--

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robert Oschler | last post by:
I have a web page where I want to make sure that an image HTTP request is successfully made before the page unloads. The request is made by setting the image element's SRC property to the desired...
2
by: Mozzie ³ | last post by:
Can 'onbeforeunload' (ie) be used to trigger a javascript? I can't find any info on how or if this is possible. Regards.
4
by: lltaylor | last post by:
Hello, Currently I use an onbeforeunload method, to do call various tidy up methods when a user exits my web application - however I now need to add additional support, for users migrating to...
12
by: Scott Mitchell | last post by:
I am using the onbeforeunload client-side event to prompt a user when leaving a page after they have made changes, as discussed in this article: Using ASP.NET to Prompt a User to Save When Leaving...
5
by: crjunk | last post by:
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...
6
by: jennyw | last post by:
Hi, I'd like to use onbeforeunload to submit a form before leaving a page. This works in Firefox and IE. Safari, however, blithely ignores this. Does anyone know of a workaround for Safari? Or...
7
by: signo | last post by:
Hello to everybody, I'm trying to make a link that closes the browser: <a href="javascript:window.close()">CLOSE</a> It works with IE6 but not with Mozilla and Netscape. Does anybody knows...
8
by: drewmania001 | last post by:
im currently using the following to prompt the user before navigating away from the page // add an unload event window.onbeforeunload = bunload; // function to prompt user function...
1
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X",...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.