mordred
05-23-2004, 01:18 PM
Hi all,
I'm a little confused about the following code:
<html>
<head>
<title>Test attachEvent</title>
<style>
body {
font-family : verdana;
font-size : 9pt;
}
</style>
<script>
function highlight(e) {
var props = [];
for (key in e) {
props.push(key);
}
props.sort();
alert(props.join("\n"));
alert(e === window.event);
}
window.onload = function() {
document.getElementById('test_normal').onchange = highlight;
document.getElementById('test_attach').attachEvent("onchange", highlight);
}
</script>
</head>
<body>
<form>
<select id="test_normal">
<option>normal</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
</select>
<select id="test_attach">
<option>attachEvent</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
</select>
</form>
</body>
</html>
What I'm trying to do is to write a script that has a cross-browser event registering and listening part. Nothing spectacular at all, but my routine to get at the event object in IE always failed because I assumed that IE doesn't get an event object passed as first parameter like in IE, and that you'd have to use the global window.event object instead. However, a check on the parameter "e" always returned "object" as type, so I wrote the test case above to see what's actually contained in the parameter.
If you try out the test code, you see that for normal/standard event registering nothing is passed to highlight(). But if I register the event with attachEvent(), I get an event-like object passed with a bunch of useful properties, but it's nt the global window.event object... how bizarre. That's not at all what I expected, though it's quite nice that it happens. :)
Can anyone provide some insight whether attachEvent() changes the event-handling model of IE, or more generally, if you are able to reproduce the described results? The MS manual doesn't mention this particular behaviour. For reference, my IE version is IE6 SP1 + various security updates.
I'm a little confused about the following code:
<html>
<head>
<title>Test attachEvent</title>
<style>
body {
font-family : verdana;
font-size : 9pt;
}
</style>
<script>
function highlight(e) {
var props = [];
for (key in e) {
props.push(key);
}
props.sort();
alert(props.join("\n"));
alert(e === window.event);
}
window.onload = function() {
document.getElementById('test_normal').onchange = highlight;
document.getElementById('test_attach').attachEvent("onchange", highlight);
}
</script>
</head>
<body>
<form>
<select id="test_normal">
<option>normal</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
</select>
<select id="test_attach">
<option>attachEvent</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
</select>
</form>
</body>
</html>
What I'm trying to do is to write a script that has a cross-browser event registering and listening part. Nothing spectacular at all, but my routine to get at the event object in IE always failed because I assumed that IE doesn't get an event object passed as first parameter like in IE, and that you'd have to use the global window.event object instead. However, a check on the parameter "e" always returned "object" as type, so I wrote the test case above to see what's actually contained in the parameter.
If you try out the test code, you see that for normal/standard event registering nothing is passed to highlight(). But if I register the event with attachEvent(), I get an event-like object passed with a bunch of useful properties, but it's nt the global window.event object... how bizarre. That's not at all what I expected, though it's quite nice that it happens. :)
Can anyone provide some insight whether attachEvent() changes the event-handling model of IE, or more generally, if you are able to reproduce the described results? The MS manual doesn't mention this particular behaviour. For reference, my IE version is IE6 SP1 + various security updates.