1

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.

1

2 Answers 2

2

With jquery you can do an ajax request:

 $('footer').load('/yourPage.html', function () {
    //if you need to do something after
 });
Sign up to request clarification or add additional context in comments.

Comments

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;

2 Comments

I tried it. But it hasn't rendered in the browser. But has external file markups added in code view
@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 developer.mozilla.org/en-US/docs/Web/API/Node/appendChild if you have text, use .innerHTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.