using addEventListener in js when not supported how be progressive in my js code and provide equivalent? I need to use moderniz lib?
Only Internet Explorer 8 (and the earlier dead versions) don’t understand event listeners. Those browsers have an attachEvent method that works in a similar way and so all you need is to do to be able to use either of them to attach all your event listeners is to simply create a function that will call one or the other depending on which the browser supports and call that function instead.
Here’s an example of a function that will use whichever of the two that the browser supports (testing which of the two is supported once only the first tile you use it):
addEvent = function(ob, type, fn ) {
if (window.addEventListener)
addEvent = function(ob, type, fn ) {
ob.addEventListener(type, fn, false );
};
else if (document.attachEvent)
addEvent = function(ob, type, fn ) {
var eProp = type + fn;
ob['e'+eProp] = fn;
ob[eProp] = function(){ob['e'+eProp]( window.event );};
ob.attachEvent( 'on'+type, o[eProp]);
};
addEvent(ob, type, fn )
};
You’d then add all your event listeners using code such as:
addEvent(document.getElementById('myid'),
'click',
myfunction);
ajax.onload=processResponse()
ajax.addEventListener(“readystatechange”, processResponse, true);
// what about the same for^? exist any other statement for this(ajax callback) expect these two?