Bueno, al tema: me he preguntado si era posible cargar varias páginas en diferentes capas y he tocado un poco la función cargarContenido()
Código :
function cargarContenido(pagina,destino){
var contenedor;
contenedor = document.getElementById(destino);
ajax = nuevoAjax();
ajax.open("GET", pagina, true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
contenedor.innerHTML = ajax.responseText;
}
}
ajax.send(null);
}
Así tendría la posibilidad de, con una misma función, cargar diferentes páginas en diferentes div. Pero nada de eso, unos exploradores cargaban la misma web en todas las capas y otros cargaban solo la primera (o la última, no lo recuerdo
Así que manos a la obra he estado investigando (sí, también le he dado a la prueba y error
Código :
function nuevoAjax(xmlhttp){
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp
}
function cargarContenido(pagina,destino){
var contenedor;
var ajax;
contenedor = document.getElementById(destino);
ajax = nuevoAjax(ajax);
ajax.open("GET", pagina, true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
contenedor.innerHTML = ajax.responseText;
}
}
ajax.send(null);
}
Si alguien quiere, explico lo que he hecho. Un saludo
