【发布时间】:2013-05-29 06:54:45
【问题描述】:
我已经上下搜索了,但我一直无法找到允许我使用以下代码调整页面高度的答案:
// Set path to the iframe file
var filePath = 'http://www.mysite.com/widget/widget.php';
// Setup the iframe target
var iframe='<iframe id="frame" name="widget" src ="http://www.mysite.com/widget/widget.php" width="100%" height="100%" marginheight="0" marginwidth="0" frameborder="no" scrolling="no"></iframe>';
// Write the iframe to the page
document.write(iframe);
var myIframe = parent.document.getElementById("frame");
// Setup the width and height
myIframe.height = 450;
myIframe.width = 255;
myIframe.src = filePath;
// set the style of the iframe
myIframe.style.border = "1px solid #dddddd";
myIframe.style.padding = "2px";
请注意“myIframe.height = 450;”将我的小部件限制为 450 像素高...我需要它来允许我的小部件调整为 100%,是的,我尝试了“100%”但它不起作用。
当我将此代码放在创建简单小部件的站点上时,会提取上面的代码。
这里是原始 javascript iframe 小部件的来源:http://papermashup.com/creating-an-iframe-with-javascript/ 但他们没有关于如何拥有 100% 高度的说明
【问题讨论】:
-
您可以使用CSS:
position: absolute/fixed并设置top+bottom: 0。 -
@Teemu 会作为样式直接添加到 iframe 中吗?
-
测试一下。如果它不起作用,请将该 CSS 用于包装器
div和100%用于iframe。 -
@Teemu 感谢您的帮助,但都不管用。
-
没有?也许是
document.write()。检查这个Fiddle。
标签: javascript iframe widget