,

IE Javscript Event Capturing

Did you know that IE doesn't pass a javascript event to the handler function? Well, it doesn't. As I learned from BrainJar's article on The DOM Event Model:

Instead of passing an Event object to a handler function, it provides a single, global object named window.event

So, for example, lets say you have a link. We'll call it "linky."

<a href="#" id="linky">test</a>

At some point you add an onclick function to linky like so:

<script>
    $('linky').onclick=handler;
</script>

With standards compliant browsers (FireFox Safari etc.), you can define the handler function like this to announce your mouse's X position:

<script>
    function handler(event){
        alert(Event.pointerX(event));  
    }
</script>

Note the above function takes the click event as a parameter. In IE, you do a little something like this:

<script>
    function handler(){
        alert(Event.pointerX(window.event));  
    }
</script>

Some of the above code ($() and Event) assumes you are using prototype.js.

Comments