1

Can I import/render a HTML file inside other HTML file?

Main file:

<html>
  <body>
    <div><!-- render other HTML file here --></div>
  </body>
</html>

Render file:

<h1>Testing</h1>

Final expected result:

<html>
  <body>
    <div><h1>Testing</h1></div>
  </body>
</html>
4
  • Why not use an iframe? Commented Jan 16, 2017 at 19:10
  • I don't want a frame, I wanna just organize better my HTML code files Commented Jan 16, 2017 at 19:11
  • you need to use JS or server-side technology if you want to do this. HTML files are static by default, if you want to load dynamic bits of your HTML, you need something else to help you with that Commented Jan 16, 2017 at 19:13
  • I think you'll want to look at something like Web Components (webcomponents.org), Polymer (polymer-project.org/1.0), Handlebars (handlebarsjs.com), or a JS framework like React, Angular, VueJS. Commented Jan 16, 2017 at 19:13

2 Answers 2

1

You can't do that so neatly with plain HTML. You would need a renderer like Node.js or Django which preprocess the page for you and send a response to the client like the one you desire.

Alternatively you could use JavaScript to gather the page through AJAX and write it on that spot. But I don't think that's worth it.

But you can use iframes to achieve more or less the same result.

Sign up to request clarification or add additional context in comments.

Comments

-1

Use an iframe with your other page's url :
<iframe src="http://www.yourotherpage.com"></iframe>

2 Comments

OP said no frames :(
Didn't saw while I was writing

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.