【发布时间】:2012-02-09 05:06:54
【问题描述】:
在使用 javascript 在加载时注入 iframe 后,我无法调整其大小。我使用了大约 300 像素的设置宽度,它可以正常工作,但动态地将 iframe 的高度调整为其内容的大小(博客文章)。
我尝试让 contentWindow(没有子 dom 元素)和 contentDocument(未定义)无济于事。
我在加载时这样做:
var iframe = document.createElement('iframe');
iframe.setAttribute('id','postFrame');
iframe.setAttribute('frameborder','no');
iframe.setAttribute('scrolling','no');
iframe.setAttribute('onload','resizeFrame();');
iframe.setAttribute('width','300px');
iframe.setAttribute('src','http://espn.go.com/espn/print?id=7454651');
var container = document.getElementById('container');
container.appendChild(iframe);
function resizeFrame(){ /* resize iframe based on content height*/ }
有没有办法根据 iframe 中的内容调整 iframe 高度的大小?
*编辑**
可能的解决方法:
有没有希望我可以使用 Access-Control-Allow-Origin 来解决问题?假设 iframe 中的页面是我自己的,或者是从 php 脚本中回显的
【问题讨论】:
-
我假设你没有 'espn.go.com',在这种情况下,我在这几个月里在这方面做了很多工作 - 它依赖于“客户”和“供应商”(您将是其中之一,espn.go.com 将是另一个)。我认为你最好私下联系我,这样我就可以在 Skype 上与你交谈。如果您在此处留下您的 Skype 用户名,那么我将添加您并尽力提供帮助。
标签: javascript html dom iframe frame