Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including external HTML file to another HTML file [duplicate]

Tags:

html

How can I insert an external html file to my file?

For instance:

<div id="header">

       Here show the external HTML code in the file, for example: name.html

</div>

Thank you very much!

like image 270
user2467899 Avatar asked Jun 17 '13 13:06

user2467899


People also ask

How do I display the content of one HTML page in another?

You could use an <iframe> in order to display an external webpage within your webpage. Just place the url of the webpage that you want to display inside the quotes of the src attribute. Show activity on this post. Either you use an iframe or you load the site via AJAX into a div (e.g. using jQuerys load() method).

Which of the following elements would you use to display another HTML document inside one HTML document?

Using HTML <iframe> tag.

HOW include HTML in HTML file in PHP?

The include (or require ) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement. Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.


4 Answers

Another way is to use the object tag. This works on Chrome, IE, Firefox, Safari and Opera.

<object data="html/stuff_to_include.html"> 
    Your browser doesn’t support the object tag. 
</object>

more info at http://www.w3schools.com/tags/tag_object.asp

like image 81
Stuart G Avatar answered Oct 17 '22 22:10

Stuart G


You can use jquery load for that.

<script type="text/javascript">
$(document).ready(function(e) {
    $('#header').load('name.html',function(){alert('loaded')});
});
</script>

Don't forget to include jquery library befor above code.

like image 28
Rajnikant Kakadiya Avatar answered Oct 17 '22 23:10

Rajnikant Kakadiya


You're looking for the <iframe> tag, or, better yet, a server-side templating language.

like image 31
SLaks Avatar answered Oct 17 '22 21:10

SLaks


The iframe element.

<iframe src="name.html"></iframe>

But content that you way to have appear on multiple pages is better handled using templates.

like image 23
2 revs Avatar answered Oct 17 '22 21:10

2 revs