Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iframes vs ajax [closed]

Tags:

ajax

iframe

Suppose i have some tabs (e.g. jquery tab) and I want to dynamically load some page in each tab, I can do that in two ways

  1. Use jquery ajax tabs (basically filling div with ajax data) or
  2. Each tab can contain an iframe and page loaded into that.

Q1. I see no difference between two approaches to user, is there?

Q2. I think iframe way is better because iframe can load any page but sometimes loading ajax data into div may not work as expected.

like image 431
Anurag Uniyal Avatar asked Apr 20 '09 13:04

Anurag Uniyal


People also ask

Why iframe should not be used?

Iframes Bring Security Risks. If you create an iframe, your site becomes vulnerable to cross-site attacks. You may get a submittable malicious web form, phishing your users' personal data. A malicious user can run a plug-in.

Are iframes out of date?

IFrames are not obsolete, but the reasons for using them are rare. Using IFrames to serve your own content creates a "wall" around accessing the content in that area. For crawlers like Google, It's not immediately clear that cotent in an iframe will be ranked as highly as if the content were simply part of the page.

Are iframes bad practice?

iframe injection is a very common cross-site scripting attack. iframes use multiple tags to display HTML documents on web pages and redirect users to different web addresses. This behavior allows 3rd parties to inject malicious executables, viruses, or worms into your application and execute them in user's devices.

Are iframes dead?

Nope, iframes are definitely not dead.


2 Answers

For one, having an error in an included page (or ajax call) is probably better to handle with the ajax approach. With iframes you'll just get an ugly 404 or 500 error in the middle of your page. But with ajax you can detect the error and display a more user-friendly error message.

It also depends on what data you're loading into your page. If you control the html being loaded in, you can avoid or fix any display issues that may arise. If you need to load a page outside of your control, iframes would be best (or necessary).

There may also be accessibility issues involved with either approach, but I'm not familiar enough with that to determine which approach works best with screen readers, etc.

like image 177
kbosak Avatar answered Sep 19 '22 16:09

kbosak


If the pages are your content, and you can control the stylesheets and everything being accessed by each one...then go with option number one. You can engineer things so you don't have to retrieve shared content more than once.

If the pages are out of your control (external sites, etc.), then load them up in iFrames. You won't have to worry about the pages rendering properly, etc.

like image 23
Justin Niessner Avatar answered Sep 16 '22 16:09

Justin Niessner