I want to include header and footer in all of my pages. I can include in php by using include() function. But I have only .html file. So is there any html markup to include another html file.
Asked
Active
Viewed 958 times
1
-
If your server supports it, you can use [Server Side Includes](http://www.yourhtmlsource.com/sitemanagement/includes.html) – Rory McCrossan Jun 26 '15 at 13:32
2 Answers
2
With jquery you can do an ajax request:
$('footer').load('/yourPage.html', function () {
//if you need to do something after
});

max890
- 517
- 2
- 9
0
Using HTML Imports
<head>
<link rel="import" href="/path/to/file/file.html">
</head>
And use it with:
var content = document.querySelector('link[rel="import"]').import;

Thyrun
- 101
- 1
- 10
-
I tried it. But it hasn't rendered in the browser. But has external file markups added in code view – Sa Si Kumar Jun 26 '15 at 13:40
-
@sasikumar you still have to insert the content into the dom somewhere. His code only stored it into the content variable. If you have a dom node use this https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild if you have text, use .innerHTML. – Corey Young Jun 26 '15 at 13:43