471,337 Members | 1,081 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Is there any idea how to prevent the next event to happen?

I attach an Event in document.onkeyup and another event in
document.onbeforeunload

in onkeyup event, if the condition is satisfied, i will activate sth,
then i don't want the onbeforeunload event to happen.

is it possible to accomplish this?

thanks!

Apr 7 '06 #1
3 1866
wrote on 07 apr 2006 in comp.lang.javascript:
I attach an Event in document.onkeyup and another event in
document.onbeforeunload

in onkeyup event, if the condition is satisfied, i will activate sth,
then i don't want the onbeforeunload event to happen.

is it possible to accomplish this?


In general the "event" in the sense of a key or mouse action can only be
prevented by forcefully restraining the user. ;-)

You can however acccomplsh your aim by changing the execution to a non
execution. [Not to a non-event]

var preventive = false;

function oneventOnkeyup (){
preventive = true
// do what you want with this event;
}

function oneventOnbeforeunload(){
if (preventive) return;
// do what you want with this event;
}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 7 '06 #2
so*********@gmail.com wrote:
I attach an Event in document.onkeyup and another event in
document.onbeforeunload

in onkeyup event, if the condition is satisfied, i will activate sth,
then i don't want the onbeforeunload event to happen.

is it possible to accomplish this?


That would depend on what you call "attach an Event". It is possible to
prevent the _event listener_ from being called (that is not preventing the
event from happening), by assigning `null' to the event handler property
if the event listener was assigned with `targetObject.onbeforeunload =
functionObjRef;':

targetObject.onbeforeunload = null;

Or IE-only, if the event listener was assigned to the target object for the
event with targetObject.attachEvent("onbeforeunload", functionObjRef):

targetObject.detachEvent("onbeforeunload", functionObjRef);

(There is no mention of a standards compliant `beforeunload' event yet,
so the methods of W3C DOM Level 2 Event should not apply, and it is
error-prone to use them here.)

Another approach is to set a flag to prevent pieces of code in the event
listener from being executed, but the event listener will be called anyway.
PointedEars
Apr 7 '06 #3
so*********@gmail.com wrote:
I attach an Event in document.onkeyup and another event in
document.onbeforeunload


Is onbeforeunload a standard event? Best I can tell, it's IE specific...

Apr 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Chris | last post: by
14 posts views Thread by Ed Jay | last post: by

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.