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!
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).
Using HTML <iframe> tag.
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.
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
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.
You're looking for the <iframe>
tag, or, better yet, a server-side templating language.
The iframe element.
<iframe src="name.html"></iframe>
But content that you way to have appear on multiple pages is better handled using templates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With