Howard Zoopaloopa
Howard Zoopaloopa

Reputation: 3822

IE 9 onhashchange Delivering Undefined Event Object

I've got a simple event listener:

window.onhashchange = function(e){
   alert(e.newURL);
}

that works great in anything but IE 9 (not testing for previous version). In IE I'm getting an undefined event object... Any idea what I'm missing? Is this not fully supported yet?

example here:

http://hupcapstudios.com/projects/hash.php#

Thanks in advance.

Upvotes: 1

Views: 1011

Answers (1)

stewe
stewe

Reputation: 42632

Some older versions of IE9 don't pass the event as an argument to the event handler, you have to get it from window.event, this should work:

window.onhashchange = function(e){
    e = e || window.event;
    alert(e.newURL);
}

Upvotes: 2

Related Questions