Bill H wrote:
> On Sep 7, 6:50 am, UKuser <spiderc...@yahoo.co.uk> wrote:
>> Can anyone tell me why this is not working, where the script is placed
>> in the header section and document.pressed=this.value; is in the
>> onClick statement of a form submit button.
>>
>> window.onbeforeunload =
>> function OnSubmitForm(){
>> if (document.pressed='Save1'){
>> return true;
>> } else {
>> return("You will lose any unsaved info");
>> }
>> }
>>
>> I'm trying to get it so that you only get the error when you make a
>> move other than clicking the Continue button.
>>
>> Any help would be great, as I'm not a javascript guru.
>
> I think you want to return false, not an error message.
No, that approach is correct (to a certain extent). A peculiarity of the
proprietary `onbeforeunload' event handler is that if the return value is
a string value, it is displayed in a message box asking whether the user
actually wants to navigate away. As a precaution against scriptkiddies,
that event cannot be canceled anymore (IIRC that change was made with
the Firefox 2.0 release). Returning `true' or another non-string value
displays the same as returning the empty string (at least in my Firefox
2.0.0.6 on Windows XP SP2).
> I could be wrong, but doesnt the submit handler just look for
> a value of true or false and default to true if false is not false?
There is no event handler for the `submit' event here.
Different event handlers require different return values. However, either
`true' or `false' are usually the values required to return in order to
prevent the default action and further bubbling (to cancel the event) this
way, depending on the event handler. For the `submit' event, it may be
possible only to return `false' to cancel the event and return another
true-value otherwise; however, I would always make that little effort and
return `true' in the latter case instead just to be on the safe side.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
|