Questa funzione crea una nuova XMLHttpRequest, possiamo usarla così com'è.
codice:
function assegnaXMLHttpRequest() {
var
XHR = null,
browserUtente = navigator.userAgent.toUpperCase();
if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
XHR = new XMLHttpRequest();
else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
if(browserUtente.indexOf("MSIE 5") < 0)
XHR = new ActiveXObject("Msxml2.XMLHTTP");
else
XHR = new ActiveXObject("Microsoft.XMLHTTP");
}
return XHR;
}
Questa è la funzione che realizzerà il cambio pagina.
Prende in ingresso un url (param) ad esempio "laura-pausini.html"
e lo inserisce nella tua pagina attuale (senza refresh!) all'interno del tag (un <div> o anche un <td>) con id "myid"
codice:
function getVal(param){
var req = assegnaXMLHttpRequest();
req.open("GET", param, false);
req.send(null);
document.geElementById('myid').innerHTML=req.responseText;
return false;
}
Quindi nel menu scriviamo
Laura Pausini
nel corpo della pagina avremo:
<div id="myid">Qui verra inserito il contenuto di 'laura-pausini.html' alla pressione del link</div>
Fammi sapere se ti gira.