Are IFrames (HTML) obsolete? [closed]

2019-01-04 09:53发布

Getting contradictory messages about that, hope they're not. I cannot imagine support for it would stop, since a gazillion sites use them.

Some additional questions about that:

  1. Why should they phase out this tag?
  2. Any alternative for it?

14条回答
女痞
2楼-- · 2019-01-04 10:24

The google gadget specification currently relies on iframes: http://code.google.com/apis/gadgets/docs/spec.html

Currently they are the only simple way to provide isolation for javascript apps that are pulled from multiple domains/providers.

Also many of the widgets that people embed on their websites from third-parties use iframes.

While they do have their drawbacks, iframes provide a pragmatic solution to common problems on the web. I'd have to guess that they will be around for some time to come.

查看更多
老娘就宠你
3楼-- · 2019-01-04 10:24

I've just changed a site from a normal Frameset to Iframes as normal frames couldn't do what I needed. It caused no issues with the rest of the codebase.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-01-04 10:25

I've seen lots of forums that suggest the Object tag as a replacement for IFrame, which probably works in most cases.

For example, I had a PDF showing in an IFrame (because there were other things we need to show on the page besides only the PDF) and was able to get it to display fine using Object.

What was:

<iframe id="confirmed_pdf" class="current_pdf" src="/prescriptions/show_pdf?id=123" height="570" width="480"></iframe>

Became:

<object id="confirmed_pdf" class="current_pdf" data="/prescriptions/show_pdf?id=123" type="application/pdf" height="570" width="480">
  <p>[Show this message if displaying the PDF did not work]</p>
</object>

But Object was not a suitable replacement to fill the requirement to be able to print ONLY the PDF portion of the page.

An IFrame is like its own window within the page (a window within a window, basically), and once you get the window object, you can call .print() on it, like:

jQuery("#confirmed_pdf").contentWindow.print();

IFrame has a contentWindow property, that's what makes printing only that part possible. Object does not have a contentWindow property, so there's no way to print only the section of the page.

So, it seems like if you're just using IFrame to display something, there's other tags like Object that can be used instead. But if you need to interact with the contents of the IFrame in certain ways, then IFrame may be necessary.

查看更多
劫难
5楼-- · 2019-01-04 10:27

IFrames are not obsolete, but the reasons for using them are rare.

Reasons for using iframes:

  • It's great for walling off other people's stuff from other domains but it doesn't integrate smoothly. (stylesheets, javascript etc...)
  • Integrating multimedia can sometimes be done easier via an iframe as opposed to using the embed tag.
  • Really, really specialized cases like gmail's case where they are using it for sounds and history management.

I would also answer that there is no need for the removal of iframes, it's a needed tag and will be around for a while.

查看更多
贼婆χ
6楼-- · 2019-01-04 10:30

Horses for courses... <iframe>s are like anything else... for the right purpose they're the right tool; for the wrong purpose they're an ugly hack, or worse.

In Ajax, <div>s are often the more appropriate container. In some places the activity of passing-off external content as part of your own site, as supported by <iframe>s, is inappropriate.

My team used an <iframe> the other day as an ideal way to give users access to their HTML e-mail history - the e-mails were complete <html> pages which we wanted to insert easily into our web template. <iframe>s were absolutely perfect for presenting that data]'.

On the other hand, <iframe>s should almost always be removed or disabled in any user-submitted content which is output back onto the site, because in that context they are a major security issue.

查看更多
姐就是有狂的资本
7楼-- · 2019-01-04 10:31

IFrames are not dead, but Frameset/Frames are dying.

In the last 2 releases of IE (IE7/IE8) zooming in Frames (not IFrames) has created disastrous results.

By all means use IFrames, but IMHO stay clear of Framesets/Frames.

查看更多
登录 后发表回答