Pruebe el siguiente código (demostración) en los navegadores IE6, IE7, Firefox2+, Firefpx3+, Opera9.6+, Safari3.1+:
<div id = prueba>
<a href =#> test </a>
</div>
<div id = resultado> </div>
<script type = text/javaScript>
(función(){
var test = document.getElementById ('test');
alerta (test.innerhtml);
resultado var = document.getElementById ('resultado');
resultado.innerhtml = test.innerhtml;
alerta (resultado.innerhtml)
}) ();
</script>
Como resultado, se encontrará que el valor href del elemento A en el resultado. Innerhtml apareció por segunda vez en los navegadores IE6 e IE7 se convierte en el camino absoluto.
De hecho, nuestros antepasados encontraron estos problemas hace mucho tiempo (gracias a Yu Bo por la información proporcionada):
La solución de procesamiento se ha mencionado en el artículo anterior, que es utilizar el método GetAttribute ('href', 2) bajo IE. Microsoft extiende el segundo parámetro a este método, que se puede establecer en 0, 1, 2, y si se establece en 2, se devuelve el valor original de la propiedad.
El script se soluciona a:
(función(){
var test = document.getElementById ('test');
alerta (test.innerhtml);
resultado var = document.getElementById ('resultado');
resultado.innerhtml = test.innerhtml;
if (/*@cc_on!@*/0) {// si es IE
Var links1 = test.getElementsBytagName ('a');
Var links2 = result.getElementsBytagName ('a');
para (var i = 0, len = links1.length; i <len; ++ i) {
links2 [i] .href = links1 [i] .getAttribute ('href', 2);
}
}
alerta (resultado.innerhtml);
}) ();
En el proceso de encontrar este problema, también busqué un error interesante encontrado por Hedger Wang: cuando el nuevo valor del atributo HREF se restablezca en IE, si el texto del enlace contiene http: // o @, su innerhtml se mostrará incorrectamente y se mostrará como el atributo de HREF establecido.
Solución alternativa (shref es el nuevo valor de href a configurar):
shref = 'http://www.hedgerwow.com';
var isMsie = /*@cc_on!@* /false;
if (isMsie) {
shref = '' + shref; // Agregar espacio adicional antes del nuevo href
};
Detalles: "Internet Explorer puede restablecer el Innerhtml de Anchor de manera incorrecta cuando se asigna un nuevo HREF"