为什么人们仍然使用iframe? [英] Why do people still use iframes?

查看:761
本文介绍了为什么人们仍然使用iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说,iframe是纯粹的邪恶(好吧,也许不那么纯粹)。他们似乎遇到了很多麻烦。是的,您的整个网站将加载一次,然后您只需加载一个页面。但是人们为此目的发明了AJAX。

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.

我发现 iframe 的最大问题之一是我无法' t粘贴到其中一个子页面的链接,因为URL从未更改(是的,我知道有一个解决方法)。第二件事,网络搜索引擎可能有问题正确索引网站。

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.

有更好的方法来设计没有(i)帧的布局。每天我都可以看到有人在问这些问题,比如如何使用jQuery访问iframe?。

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?".

那么iframe有什么好处?还有什么理由继续使用它们?我只想知道原因:)

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

(因为它不是一个真正的问题,它是一个CW)

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

推荐答案

我可以想到两个原因(目前)为什么人们仍会使用iframe代替AJAX:

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

1) iframe绕过跨域原始策略(图像,脚本和样式不会)。这对于相对安全地从其他域名中提取站点/内容非常有用。基本上,这允许能够直观地显示来自其他域的数据,而不会让他们无限制地访问您的页面(就像JSONP能够做的那样)。

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)您可以从iframe中加载多种类型的资源,而不仅仅是某些mime类型(您相对限制为application / javascript,application / x-javascript,text / css,text / xml,image / png,image / jpeg,带脚本的图像/ gif,XHR,图像和来源)。例如,如果我想向您显示PDF,我可以打开iframe并让Adobe Reader插件显示该文件。另外,在同一个域中,如果我想将脚本,样式和图像一起管道化(在页面上内嵌,图像必须是数据URI),我可以使用iframe完成此操作(如果它在同一个域中)域名,端口和协议我也可以使用JavaScript访问它。

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).

您是否知道Gmail是一组iframe?可见部分只是巧妙的定位。此外,许多OAuth实施(Twitter,Facebook,Google,Yahoo!)通常使用iframe将其域上的用户与成功的身份验证URL相关联(用户登录后)。

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).

这篇关于为什么人们仍然使用iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆