Reasons for not using IFrame?

2019-03-14 15:30发布

are there any reasons not to use iframes at all? I currently use it to load a page from a different server (a sign up page - part of a distributed application) to provide a seamless experience. Is using iframes considered bad practice or is its use OK?

标签: iframe
7条回答
冷血范
2楼-- · 2019-03-14 15:59

IFrames are a great way to "include" external content in a web page. However, there are a couple of (small) drawbacks:

  • Security sandboxing will cause problems with JavaScript if the IFrame does not originate from the same domain.
  • You cannot get CSS to co-operate between the IFrame and the parent page, unless you control the stylesheets themselves.
  • From an indexing point of view, the IFrame's content doesn't exist.
  • Screen readers might not like the IFrame, for the same reason. Or they won't be able to properly indicate the relative meaning of an IFrame's contents.

Apart from that, they're great! The points I mentioned might even be considered advantages, if you think about it (except the screen reader one): in principle, an IFrame can't influence its parent page's layout, and it isn't influenced itself by its parent either.

查看更多
Bombasti
3楼-- · 2019-03-14 16:02

The iframe is a great tool. It enjoys near-universal browser support, it's easy to implement and has a number of useful functions. As with any other HTML element, it can be abused, but wielded intelligently it can play a part in a solid UI.

Some developers might argue to use AJAX instead, and in some situations that may be the more appropriate approach, but AJAX is not a panacea and iframes can be a far simpler implementation which has the same end-result for your users. Do whatever is simplest first, and only change that when you can verify how and why that is not working.

查看更多
Bombasti
4楼-- · 2019-03-14 16:03

Keep using iframes. Here's an example of why:

The whole Verified By Visa thing really annoys me. I'm happily shopping at some site that I trust, when I'm redirected to some site I've never heard of (not visa.com) and I have to fill in some other form and hope that I get redirected correctly back to the shopping site.

Then recently I was shopping at the John Lewis website, and they brought up the Verified By Visa page in an iframe - wonderful! I'm still looking at the John Lewis site, and all that's happening is I'm being asked for my Verified By Visa password - no problem.

Although as a web developer I know that there's no technical difference between that and a plain old redirect-there-redirect-back, the user experience is so much better!

查看更多
叼着烟拽天下
5楼-- · 2019-03-14 16:05

Pros:

  • Helps with slow third-party content like badges and ads
  • Security sandbox
  • Download scripts in parallel

Cons:

  • Costly even if blank
  • Blocks page onload
  • Non-semantic

Source: Best Practices for Speeding Up Your Web Site

查看更多
放荡不羁爱自由
6楼-- · 2019-03-14 16:05

iframes have access to certain properties of the parent document, e.g. redirect the parent frame to a new location using parent.location.href or parent.window.location (IE allows to restrict that).

This is great for phishing attacks when embedding content from other servers (even if you trust that server it might be compromised).

iframes can also be used for a variety of other attacks: IFrames security summary.

查看更多
贪生不怕死
7楼-- · 2019-03-14 16:07

As a general rule, iframes are a bad experience for SEO reasons. So, you ask is there any reason not to use iframes? Yes, if you use iframes you are losing some organic placement in the search engines.

Of course, there are usability concerns which can (and should) trump SEO value of pages.

查看更多
登录 后发表回答