1

My original goal was to add (to learn how to add) to all pages in a website a sidebar. I am now able to do it, in at least one way, with the use of some help.

But I have a slightly more general question.

Assume that we have two pages main.html and other.html, and that other.html contains some element (what is the proper term? node?), say

<htmltag id="theid" class="itsclass">
...
</htmltag>

[The example has id and the class in case the explanation is going to make use of them.]

I would like to know what is the proper, or current, or modern way for main.html to get this node (element) form other.html and add it to its own body.


Currently I am doing this: main.html has an iframe with src="other.html" and hidden="true". Then with iframe.contentWindow.document.getElementById I am capturing the htmltag I want, and with document.importNode and document.body.insertBefore or document.body.appendChild I add it to the body.

I heard, though, criticism about using iframe.

I heard also about other possible candidates for doing this job (some I have tried only a little, some I haven't began reading about):

  1. Angular imports
  2. XMLHttpRequest.

I heard about import here. But also about it not being supported.

  1. Other posts in questions talking about jQuery, PHP, or other things running in the server side.

  2. I just learned about object here. This one seems pretty simple (well, iframe seems also simple). Actually I just tried it and it works nicely. Any comments on the suitability of this option?

To much divergent information for a beginner. I would like to do the importing in the simplest, and most current, way that the HTML allows. Hopefully using only HTML and JavaScript, if possible.

Could someone kindly try to give me some orientation?

Community
  • 1
  • 1
beginner123
  • 105
  • 6
  • 1
    About the html tags (4): [http://stackoverflow.com/q/16660559/5230059](http://stackoverflow.com/q/16660559/5230059) – Ron C Oct 04 '15 at 06:42
  • @RonC Interesting. So, between `iframe` and `object`, the `iframe` is the one closer to the answer. – beginner123 Oct 04 '15 at 06:57

0 Answers0