将父网址传递给iframe - iframe自动调整大小

时间:2012-03-05 14:29:38

标签: javascript url iframe autosize

我正在使用我在stackoverflow上找到的解决方案,该解决方案会根据内容自动调整iframe大小。

https://stackoverflow.com/a/362564/258594

我的iframe被多个网站使用,所以我需要调用帮助文件来动态而不是硬编码。如何将父网址传递给我的iframe以更改以下行。

pipe.src = 'http://www.foo.com/helper.html?height='+height+'&cacheb='+Math.random();

2 个答案:

答案 0 :(得分:1)

结束将网址添加到iframe src

<iframe width="100%" height="100%" src="foo.html#http://www.ParentURL.com"></iframe>

然后在iframe srouce文件中访问它

URL = window.location.hash.substr(1);
var height = document.body.scrollHeight;
var pipe = document.getElementById('helpframe');
pipe.src = URL + '/helper.html?height='+height+'&cacheb='+Math.random();

答案 1 :(得分:0)

第一个解决方案

<iframe width="100%" height="100%" src="foo.html"></iframe>

第二个解决方案

<iframe width="auto" height="auto" src="foo.html"></iframe>
  

foo.html

<body>
<div style="width:200px;height:300px;">
<p>Your all content</p>
</div>
</body>
相关问题