Home >Web Front-end >JS Tutorial >How to Load HTML Pages into DIVs with JavaScript?
Loading HTML Pages into DIVs with JavaScript
It is possible to load an HTML page into a div element using JavaScript. For example, the following code will load home.html into the div with>
<br><div><pre class="brush:php;toolbar:false"><a href="#" onclick="load_home()">HOME</a></p> <p></div><br><div></div><br><script><br> function load_home() {</p> <pre class="brush:php;toolbar:false">document.getElementById("content").innerHTML='<object type="text/html" data="home.html"></object>';
}
This will work in Firefox, but in Google Chrome, it will ask for a plugin to be installed. To fix this, change the type attribute of the object to text/html. This will cause Chrome to load the HTML page without requiring a plugin.
The final code looks like this:
<br>function load_home() {<br> document.getElementById("content").innerHTML='<object type="text/html" data="home.html"></object>';<br>}<br>
The above is the detailed content of How to Load HTML Pages into DIVs with JavaScript?. For more information, please follow other related articles on the PHP Chinese website!