将iframe设置为远程内容的内容高度 [英] Set iframe to height of content for remote content

查看:108
本文介绍了将iframe设置为远程内容的内容高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使您的iframe完全适合您的内容(使用JavaScript)的问题已在论坛上得到解答...... 仅针对显示来自同一域的内容的iframe

The question of how to make your iframe fit 100% of your content (using JavaScript) has been answered on the forum already... for iframes displaying content from the same domain only.

我的问题:当iframe src属性用于包含框架的页面域之外的页面时,是否可以调整iframe的大小以适应内容?围绕跨站点脚本编写的浏览器安全功能使我无法访问iframe的文档对象。

My questions: Is it possible to resize an iframe to fit the content when the iframe src attribute is for a page outside of the domain of the page containing the frame? The browser security features surrounding cross-site scripting prevent me from accessing the document object for the iframe.

我正在寻找任何有创意的解决方案。我的一个想法是以某种方式检测到在iframe上可见的滚动条,并逐渐增加高度,直到它们没有。不幸的是,我找不到任何方法来检测可见的滚动条。想法?

I'm looking for any creative solution. One of my thoughts was to somehow detect that scrollbars were visible on the iframe, and to incrementally increase the height until they weren't. Unfortunately I can't find any way to detect visible scrollbars either. Ideas?

请注意我正在寻找客户端解决方案。

Please note that I am looking for a client-side solution.

回复:

问题仍然存在 - 我不知道提前远程文档的高度,所以我无法从数据库或查询字符串值设置它。

The problem still exists - I don't know the height of the remote document ahead of time, so I can't set it from a database or querystring value.

CSS中iframe的100%不会将其设置为内容内部 iframe的100%,而是相对于页面或包含元素(即div或其他东西)。

100% on the iframe in CSS will not set it to 100% of the content inside the iframe, but relative to the the page or containing element (i.e., a div or something).

推荐答案

(我对一个类似的问题

不可能没有一些控制就可以做到这一点由于浏览器的安全模型,页面被iframed。如果有可能,这将是一个安全问题,并且必须修复。

It is not possible to do this without some control over the page being iframed because of the browser's security model. If it was possible, that would be a security problem and would have to be fixed.

尽管嵌入网站嵌入在第三方网页的高度时让它知道页面似乎无害,这可能会泄漏信息到浏览器用户想要保密的嵌入网站。例如, http://www.facebook.com/ 呈现的方式会有所不同,具体取决于您是否已登录在,所以,如果我的网站可以计算< iframe src =http://www.facebook.com/> 的高度,那么我可以弄清楚是否或者你不是facebook用户,你可能不想让我知道。

Although letting the embedding site know the height of a third party webpage when embedded in the page seems harmless, this can leak information to the embedding site that the browser's user wants to keep private. For example, http://www.facebook.com/ renders differently depending on whether or not you are logged in, so if my website can work out the height of <iframe src="http://www.facebook.com/"> then I can work out whether or not you are a facebook user, something you probably don't want me to know.

信息泄露与臭名昭着的 CSS历史漏洞浏览器供应商必须插入。

The information leakage would be similar to the infamous CSS History Leak which browser vendors had to plug.

这篇关于将iframe设置为远程内容的内容高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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