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>
gFontaniva
  • 897
  • 11
  • 27
  • Why not use an iframe? – dev8080 Jan 16 '17 at 19:10
  • I don't want a frame, I wanna just organize better my HTML code files – gFontaniva Jan 16 '17 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 – blurfus Jan 16 '17 at 19:13
  • I think you'll want to look at something like Web Components (https://www.webcomponents.org/), Polymer (https://www.polymer-project.org/1.0/), Handlebars (http://handlebarsjs.com/), or a JS framework like React, Angular, VueJS. – leocreatini Jan 16 '17 at 19:13

2 Answers2

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.

zurfyx
  • 31,043
  • 20
  • 111
  • 145
-1

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

BDeliers
  • 74
  • 1
  • 12