strange event handling problem in IE

Y

yb

Hi,

In IE I usually check for event objects in event handlers with
something like:

handler = function( e ) {
if( !e ) var e = window.event;
....
}

I am also using IE 'attachEvent' to register the event handler.
However, IE (6) passes in an empty 'e' object, and not an undefined
value. Has anyone had this problem before. I've only noticed it
recently, and I'm wondering if the windows update changed something in
IE. I'm now forced to check for both e, and the relevant property,
e.g. e && e.target

My IE version is:

6.0.2900.2180.xpsp_sp2_gdr.050301-1519
 
W

web.dev

yb said:
Hi,

In IE I usually check for event objects in event handlers with
something like:

handler = function( e ) {
if( !e ) var e = window.event;
....
}

Not strange at all. IE has never passed an 'e' object to an event
handler. Other browsers, such as FireFox do. That is why you check to
ensure whether or not 'e' is defined, if it's not, used IE's
window.event to assign it to 'e'.
 
Y

yb

My point is that IE *is* passing in the 'e' object.

I'm getting an e object passed in from IE, so the check

if( !e ) var e = window.event

does not assign window.event to e, and all event handling fails.
The e object passed in is empty with no properties but not undefined
 
R

Robert

yb said:
Hi,

In IE I usually check for event objects in event handlers with
something like:

handler = function( e ) {
if( !e ) var e = window.event;
....
}

I am also using IE 'attachEvent' to register the event handler.
However, IE (6) passes in an empty 'e' object, and not an undefined
value. ...

My IE version is:

6.0.2900.2180.xpsp_sp2_gdr.050301-1519

I have the same version as you, but IE does not pass an empty event
object for me.
Reinstall IE? Or maybe there is some other js code that interferes with
the event.
 
Y

yb

He uses attachEvent in which case IE6 does pass an event object.

What information does this object include? I haven't found anything in
msdn docs about it.

Perhaps a bug? I haven't had time to test this further, but I'm pretty
sure this object was empty.
 
V

VK

Robert said:
I have the same version as you, but IE does not pass an empty event
object for me.
Reinstall IE? Or maybe there is some other js code that interferes with
the event.

It is not an empty object. It's the same "event" object you can get as
global variable.

Traditionally IE provided event info via automatically created
contextually global variable "event" and Netscape > Gesko via
automatically assigned first argument in the event handler. But
starting IE 6.0.2800 (at least) it implements both ways, so you could
access event info in IE-way or Gesko-way. Very confusing and dangerous
actually, but I guess that the intentions were to facilitate developers
life :) :-(

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

<script type="text/javascript">

function init() {
document.getElementById('ie').attachEvent('onclick',testIE);
}

function testIE(e) {
alert(e.srcElement.tagName);
alert(event.srcElement.tagName);
}

window.onload = init;
</script>

<style type="text/css">
body {background-color: #FFFFFF}
var {font: normal 10pt Verdana, Geneva, sans-serif;
color: #0000FF; text-decoration: underline;
cursor: hand; cursor:pointer}
</style>

</head>

<body>

<noscript>
<p><font color="#FF0000"><b>JavaScript disabled:-</b><br>
<i><u>italized links</u></i> will not work properly</font></p>
</noscript>

<p>
<var id="ie">Test</var>
</p>

</body>
</html>
 
Y

yb

Sorry my wording was not accurate

yes, I have looked into the docs, what I meant is I could not find
information about IE passing in an object into the event handler.

On further testing, the object seems to be same as window.event, but I
can't find anything on msdn mentioning that it passing an event object
to the function as a paramter.
 
R

Robert

VK said:
It is not an empty object. It's the same "event" object you can get as
global variable.

Did you respond to me or the original poster?
Because I just said that I do not have an empty object.
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top