Home >Web Front-end >JS Tutorial >How to Load HTML Pages into DIVs with JavaScript?

How to Load HTML Pages into DIVs with JavaScript?

Linda Hamilton
Linda HamiltonOriginal
2024-11-30 02:55:14173browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn