1

I need to make changes to an existing project that uses iFrames to dynamically load external html files. However, the html files are part of the same project, not external sites. If I'm not mistaken, iFrames are considered a terrible way of loading html content unless they are used to actually display external sites.

I have looked into web components but apparently, browser support is still spotty and unfortunately, I need to support IE9.

I know that the JQuery load() method can accomplish this but in my online research, that doesn't often come up as a proper way of loading external html in general and a proper replacement for iFrames in particular.

Is there a reason why JQuery shouldn't be used here and are there better and established ways of doing this? For example, I once saw a framework that dynamically built the interface out of separate "partials" but I don't remember which framework that was.

  • _'If I'm not mistaken, iFrames are considered a terrible way of loading html content unless they are used to actually display external sites.'_ You're mistaken. – j08691 Apr 26 '17 at 14:57
  • _"I know that the JQuery load() method can accomplish this but in my online research, that doesn't often come up as a proper way of loading external html in general and a proper replacement for iFrames in particular."_ Where'd you get that? – j08691 Apr 26 '17 at 14:57

2 Answers2

3

It depends on the HTML -

If it's built like a full page - then iFrames are actually a decent solution - Also, iframes with the same origin let you have full control over the content from the parent, while still protecting CSS and JS variables which is pretty convenient.

If not - jQuery.load() will do the trick, you can also do it manually ofc, but if you already have jQuery in your project, just use it.

PiniH
  • 1,901
  • 13
  • 20
1

The load() function is almost always the best way to go, if you are encountering a specific issue using that function maybe you can share it?

Yehuda Schwartz
  • 3,378
  • 3
  • 29
  • 38
  • 1
    I have not encountered any particular issues with it, it just didn't come up as a de-facto best practice of doing this sort of thing or as an alternative to iFrames. I've never worked on a project that needed to swap page content dynamically (although I've worked quite a bit with jQuery and know that it makes dynamic updates pretty easy), so I'm mostly looking for confirmation that it's a good method to use and possibly some best practices on how to set up the project. – Guybrush Threepwood Apr 26 '17 at 15:59