Click to See Complete Forum and Search --> : problems with window.event.returnValue


mark_l_sanders
07-30-2005, 12:43 PM
I'm using window.event.returnValue to cancel a default action in IE.
IE (v6 - xp pro sp2) has no problem setting this value to 'false', but when I try to detect support for this property it fails.
In other words, the following code fails:

if(window.event && window.event.returnValue){window.event.returnValue = false;}

but the following succeeds:

if (window.event){window.event.returnValue = false;}

What's going on - surely if IE supports an object enough to set it it should also be able to detect it!!

Any clues?

Orc Scorcher
07-30-2005, 02:26 PM
The default value for returnValue is 'undefined', which is equal to false in boolean expressions. Try 'if ("returnValue" in event)' instead, but that's not backwards compatible with IE5 or older.

mark_l_sanders
07-30-2005, 03:29 PM
Orc Scorcher - I was about to say 'No, no, you must be mistaken' because I've seen the MSDN claim that the default value of returnValue was 'true'!!
However, I've been trying to validate your assertion and I found it in the discussion of the Danny Goodman / O'Reilly DHTML book (see http://www.dannyg.com/support/update9.html#page163).

So you are a genius - thanks very much indeed...

mark