Are iframes a terrible idea? [closed]

2019-01-21 19:41发布

I'm building a widget, and I've been using iframes to present content within it. At some point, I might start serving third party HTML and JS, so I thought iframes would be a good idea.

It does make the widget javascript a little more complicated, and I'm concerned that this might not be the best implementation.

Do you have any advice? It would be a huge help to hear what other people think about iframes.

16条回答
贪生不怕死
2楼-- · 2019-01-21 20:07

There is a significant issue with iframes that hardly gets a mention but which bugs the stuffing out of me.

Our colleague has a lifetime of work invested in a dynamically changing database which we have loaded into Google Docs spreadsheets which we then display on our site alongside a lot of supporting material.

There is absolutely nothing to stop someone grabbing the iframe code out my page source and shoving it onto their page. Now they are getting all our data, refreshed right up to a few minutes ago, served to their page for absolutely nothing at all.

If a google iframe could be tied to a specific domain, that would stop that in its tracks.

Any ideas, bright sparks?

查看更多
唯我独甜
3楼-- · 2019-01-21 20:08

Before XMLHTTPRequest became widely used, people were using a combination of JavaScript and iframes to serve up content in a dynamic fashion without doing full page refreshes.

There's lots of information about developing sites this way so you should have a relatively easy time of it finding workaround to a lot of the snags that you are likely to hit.

The one thing that I have found to be a pain is cross-domain use of JavaScript in iframes. If the page you embed in the iframe is from a different domain than the "parent" page, browsers have security restrictions against letting you access one from the other. The trick is for both pages to declare

document.domain = 'somedomain.com';

There's plenty of stuff on the Web about this kind of workaround.

Good luck!

查看更多
该账号已被封号
4楼-- · 2019-01-21 20:09

iframes, like frames, are just controls to use for the task at hand. As such, it is neither good nor bad in itself, but could be good or bad based on the task at hand and the client's requirements. As far as I know, all modern browsers (and non-linux users) will be able to "see and consume" iframes without a problem.

查看更多
Evening l夕情丶
5楼-- · 2019-01-21 20:10

Not necessarily, as long as the content within the iframe is predictable.

查看更多
登录 后发表回答