Ciao cavicchiandrea grazie per la segnalazione. Avevo già letto l'articolo in passato cmq e non ho ancora trovato la risposta che cercavo. Provo a fare un esempio, vediamo se riusciamo a chiarirmi le idee.
Questa è una funzione che ho creato, un getElementById cross Browser
Codice PHP:
function gel(id)
{
try
{
return(document.getElementById(id));
}
catch(e)
{
try
{
return(document.all[id])
}
catch(e)
{
alert('Your browser doesnt\'t support any of the element's getter methods. The error was: '+e);
}
}
}
Con Firefox 2, per aggiungere questa funzione all'oggetto document e bastato scriverla in questo modo
Codice PHP:
Document.prototype.gel = function (id)
{
try
{
return(document.getElementById(id));
}
catch(e)
{
try
{
return(document.all[id])
}
catch(e)
{
alert('Your browser doesnt\'t support any of the element getter methods. The error was: '+e);
}
}
}
Per testarla ho usato il seguente codice:
Codice PHP:
<body>
<div id="div"></div>
<script>
var test = document.gel('div');
alert(test);
</script>
</body>
Perfettamente funzionante su firefox ( non so, magari è una coincidenza che funzioni... ) ma non su IE6 ( e 7 anche ).
Da notare che su FF funziona anche se al posto di Document scrivo Object.
Come si fa a rendere il tutto funzionante su ogni browser?
Tnx