Ciao a tutt*,
vorrei chiedere un favore a tutto il forum. C'è qualcuno che ha una vecchia versione di IE (anche molto vecchia) installata sul proprio PC? Sto cercando di testare un codice di compatibilità dei metodi DOM element.addEventListener e element.removeEventListener con browser Microsoft che non supportano neppure i metodi element.attachEvent e element.detachEvent introdotti con le ultime versioni di IE. Si tratta semplicemente di aprire questa pagina che incollo di seguito con un vecchio browser di IE e cliccare sul testo "Clicca qui!". Se non succede nulla vuol dire semplicemente che non funziona
Vi pregherei però, se vi va, di postare anche il tipo di errore riscontrato dal browser. Ovviamente specificate anche la versione di IE che state usando! Non vi costa nulla, solo qualche secondo
Grazie in anticipo 
codice:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Codice di compatibilit&agrave; addEventListener</title>
<script type="text/javascript">
if (!Element.prototype.addEventListener) {
var oListeners = {};
function runListeners(oEvent) {
if (!oEvent) { oEvent = window.event; }
for (var iLstId = 0, iElId = 0, oEvtListeners = oListeners[oEvent.type]; iElId < oEvtListeners.aEls.length; iElId++) {
if (oEvtListeners.aEls[iElId] === this) {
for (iLstId; iLstId < oEvtListeners.aEvts[iElId].length; iLstId++) { oEvtListeners.aEvts[iElId][iLstId].call(this, oEvent); }
break;
}
}
}
Element.prototype.addEventListener = function (sEventType, fListener /*, useCapture (will be ignored) */) {
if (oListeners.hasOwnProperty(sEventType)) {
var oEvtListeners = oListeners[sEventType];
for (var nElIdx = -1, iElId = 0; iElId < oEvtListeners.aEls.length; iElId++) {
if (oEvtListeners.aEls[iElId] === this) { nElIdx = iElId; break; }
}
if (nElIdx === -1) {
oEvtListeners.aEls.push(this);
oEvtListeners.aEvts.push([fListener]);
this["on" + sEventType] = runListeners;
} else {
for (var iLstId = 0, aElListeners = oEvtListeners.aEvts[nElIdx]; iLstId < aElListeners.length; iLstId++) {
if (aElListeners[iLstId] === fListener) { return; }
}
oEvtListeners.aEvts[nElIdx].push(fListener);
}
} else {
oListeners[sEventType] = { aEls: [this], aEvts: [ [fListener] ] };
this["on" + sEventType] = runListeners;
}
};
Element.prototype.removeEventListener = function (sEventType, fListener /*, useCapture (will be ignored) */) {
if (!oListeners.hasOwnProperty(sEventType)) { return; }
var oEvtListeners = oListeners[sEventType];
for (var nElIdx = -1, iElId = 0; iElId < oEvtListeners.aEls.length; iElId++) {
if (oEvtListeners.aEls[iElId] === this) { nElIdx = iElId; break; }
}
if (nElIdx === -1) { return; }
for (var iLstId = 0, aElListeners = oEvtListeners.aEvts[nElIdx]; iLstId < aElListeners.length; iLstId++) {
if (aElListeners[iLstId] === fListener) { aElListeners.splice(iLstId, 1); }
}
};
}
</script>
</head>
<body>
<span id="cliccami" style="cursor:pointer;color:#0000ff;text-decoration:underline;">Clicca qui!</span></p>
<script type="text/javascript">
var oElemento = document.all ? document.all.cliccami : document.getElementById("cliccami");
function prova1() {
alert("Prova numero 1 riuscita!!");
}
function prova2() {
alert("Prova numero 2 riuscita!!");
}
oElemento.addEventListener("click", prova1, false);
oElemento.addEventListener("click", prova2, false);
oElemento.removeEventListener("click", prova2, false);
oElemento.addEventListener("click", prova2, false);
</script>
</body>
</html>
P.S. Se non funziona, prima di postare l'errore, potreste riprovare anche sostituendo tutte le occorrenze di "Element.prototype" con "Object.prototype"? Basta cliccare su sostituisci nel proprio editor di testo… Thnx.