Robert wrote:
yb wrote: 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.
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>