Come si carica una pagina HTML in un <div> usando JavaScript?
Voglio che home.html sia caricato in <div id="content">
.
<div id="topBar"> <a href ="#" onclick="load_home()"> HOME </a> </div>
<div id ="content"> </div>
<script>
function load_home(){
document.getElementById("content").innerHTML='<object type="type/html" data="home.html" ></object>';
}
</script>
Questo funziona bene quando uso Firefox. Quando uso Google Chrome, mi chiede il plug-in. Come faccio a farlo funzionare in Google Chrome?
143
3
Finalmente ho trovato la risposta al mio problema. La soluzione è
Potete usare la funzione jQuery load:
Scusa. Modificato per l'on click invece che on load.
Fetch API
XHR API
in base ai tuoi vincoli dovresti usare ajax e assicurarti che il tuo javascript sia caricato prima del markup che chiama la funzione
load_home()
.Riferimento - davidwalsh
MDN - Usare Fetch
[JSFIDDLE demo](http://jsfiddle.net/jpmCz/)