Why do people still use iframes? [closed]

2019-01-12 17:19发布

For me iframes are pure evil (well, maybe not so pure). They seems to make a lot of troubles. Yes, your whole site will load once and then you can just load a single pages. But people invented AJAX for this purpose.

One of the biggest issues I found with iframe was that I couldn't paste a link to one of the subpages, because the URL never changed (yes, I know there is a workaround for this). Second thing, web search engines may have problems to index that sites correctly.

Sometimes the accessibility of this sites are worse and some browser can even display them improperly.

There are better ways to design layout without (i)frames. Everyday I can see some one asking at SO questions, like "How to access iframe with jQuery?".

So what are benefits of iframes? What reason can it be to still use them? I just would like to know why :)

(since it is not a real question, it's a CW)

标签: iframe
12条回答
爷、活的狠高调
2楼-- · 2019-01-12 17:29

I can think of 2 reasons (at the moment) why people would still use iframes instead of AJAX:

1) Iframes circumvent the cross domain origin policy (images, scripts, and styles do not). This can be useful for pulling in sites / content from other domain names relatively safely. Basically, this allows the advantage of being able to visually show data from other domains without letting them stomp all over your page with unlimited access (like something like JSONP would be able to do).

2) You can load multiple types of resources from within an iframe, not just certain mime-types (you're relatively limited to application/javascript, application/x-javascript, text/css, text/xml, image/png, image/jpeg, image/gif with scripts, XHR, images, and sources). For instance, if I want to show you a PDF, I can open an iframe and let the Adobe Reader plugin show you that file. Additionally, in the same domain, if I want to pipeline a script, style, and image all together (inline on the page, image would have to be data URI), I can accomplish this with an iframe (and if it's in the same domain, port, and protocol I can access it with JavaScript as well).

Did you know that Gmail is a set of iframes? The visible part is just clever positioning. Additionally, many OAuth implementation (Twitter, Facebook, Google, Yahoo!) usually use iframes to associate a user on their domain with a successful authentication URL (for after the user logs in).

查看更多
Bombasti
3楼-- · 2019-01-12 17:33

Framesets are outdated as of HTML 5, and sometimes you need to have a frame with another site within a site. Also AJAX can only do so much. Try uploading a file to a site on another domain through https without an iframe. AJAX won't help you there.

查看更多
贪生不怕死
4楼-- · 2019-01-12 17:34

In addition to others reasons, I have one specific usage of iframe in my application. Unfortunately, the target browser in my case is Internet Explorer 6. I need to have a footer and a header that are fixed in my web pages. The main part of this page is scrollable.

However, there is a bug in IE6 where I cannot display a div element on top of select elements using the z-index CSS property. Thus, I need to create an iframe that will be used as a hack to avoid this problem.

Of course, this is a really specific usage of iframe and only concern IE6...

查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-12 17:34

I was building a social network and i see iframes being useful for widgets to put on other peoples website to show like a mini profile or integrate with the content on a remote server. Seems like the most simple way to build this. I know some widgets use JavaScript. Also with the iframe method the session is the same as visiting the site like normal, so great for like buttons.

查看更多
干净又极端
6楼-- · 2019-01-12 17:37

IFRAMEs are used to embed and isolate third-party content into a website.

Most of web advertising solutions are based on iframes - because they give security (cross-domain policy) and isolated rectangle on screen which can be fully managed by third party content and scripting (a common use case is advertisments).

Another modern use of IFRAMES is a management of history (common back button workaround) of AJAX applications.

FRAMEs are poor version of IFRAMES. Their use is declining.

查看更多
叛逆
7楼-- · 2019-01-12 17:39

I use them on ajax websites, when I need to upload files without reloading the page.

查看更多
登录 后发表回答