1

What is the best way load a full page of data including extra external JS files into the current page? I know how to do it but which way is better? An iFrame or Div? At the moment I am jQuery Ajaxing data into a Div. Then toggling this div when not needed.

Adamz
  • 96
  • 8
  • 1
    If you want a fully functional page including working JS - use IFRAME – Yuriy Galanter Oct 07 '13 at 01:22
  • Hello Currently I have no problem using JS internal or external when inserted into Divs, I use what is described halfway down the page here http://stackoverflow.com/questions/14735762/load-html-page-dynamically-into-div-with-jquery by user957863 using – Adamz Oct 13 '13 at 17:04

2 Answers2

0

an iframe is used to be used for containing media files/content. such as pdf, flash, image, video, etc. iframe can be used for containing html, but it wont be a great deal to have a great result(except you really need to do it). if you want to embed/attach external html page i think you should use div element. but if you want to add a media content into your web page, you should use iframe element. You can create a toggle button using javascript. The JS that you want to embed can be embedded on your main page(master page that contains attached files/contents) or on the page that you want to embed. But be careful, don't attach two or more JS that has the same function, it will make your browser confused (ex : you attach jqueryUI-1.9.0 and jqueryUI-10.0.2).

Oki Erie Rinaldi
  • 1,835
  • 1
  • 22
  • 31
  • 2
    Not good idea if the external page uses same CSS classes. Better is using iframe instead – bksi Oct 07 '13 at 01:41
0

I would advise against iFrames if they can be avoided. Download all of your JS libraries on the initial page load. You'll run into availability issues if you AJAX them in

Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248
  • IFrames can stop things getting messy, I was kind of asking why are iFrames so bad? With web apps SEO does not come into it and you can still target elements vice versa almost as easy. It is a good point about the JS all being in the initial page load, Minified JS is small enough to not care about on initial load so there is no reason for me to be loading it in chunks. I am making a web app that loads some large picture galleries to choose from in Colorbox iFrame. But other things like the choice of templates I am loading in Divs. – Adamz Oct 13 '13 at 20:06
  • @AdamRidley They were used mostly in the past to serve dynamic page loads (changing something or uploading a file without leaving the current page). This is redundant and for all practical purposes deprecated now since AJAX / JavaScript have been adopted. You'll also notice a lot of sites block their pages from being loaded using iFrames (StackOverflow does this) – Lloyd Banks Oct 13 '13 at 23:00