does anyone know how works the obj.attachEvent on ie?
I tried a few examples but they don't work. Also is this compatible with ie7?
What i tried is this :
var onload = function( ) {
console.log("intercepting: " + this.status + " " + this.responseText);
};
if($.browser.msie){
console.log("it's IE...");
this.attachEvent("load", onload);
}
All above inside an XMLHtppRequest.
For
attachEvent
, you need to prefix the event name with"on"
, e.g.This differs from the DOM Events'
addEventListener
, which requires the"on"
to be omitted.As Marcel pointed out, for XMLHttpRequests you need to bind to
onreadystatechange
instead, and check thereadyState
property inside the handler.onload
isn't supported forXMLHttpRequest
.On another note, you should avoid checking the browser and check feature support instead. Internet Explorer 9 supports
addEventListener
, for instance:In reality though, you wouldn't use
attachEvent
oraddEventListener
on an XHR object; I doubt IE7 and lower will play nice with this, so you would just bind to the event property directly:You probably want to assign that function to
xhrObject.onreadystatechange
.