使用javascript和div innerhtml调整iframe大小以匹配帧源

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用javascript和div innerhtml调整iframe大小以匹配帧源相关的知识,希望对你有一定的参考价值。

Post a stripped down version of the page if you can. One that shows exactly how the iframe fits into the structure of the page.

The solution I settled on works like this:
The parent page has a javascript function like this:

function insertIt() {
var _y = document.getElementById('framediv');
var _x = window.frames[0].document.body.innerhtml;
_y.innerHTML = _x
}
Then, the parent page has a div with the id "framediv" which is placed where the contents of the iframe should appear on the page.
The iframe element is then placed inside the div, like this:





As you can see, there's onload="insertIt()" inside the iframe element. So when the iframe loads, the parent page immediately takes the contents of the body of the document contained in the iframe and actually replaces the iframe element with that content.

It's a little tricky to comprehend, but it works great.

You said you're a newbie, does this make any sense to you?

also, is the iframe document located on the same server and the same domain as the parent page?
That will play a part.
  1. function insertIt() {
  2. var _y = document.getElementById('framediv');
  3. var _x = window.frames[0].document.body.innerHTML;
  4. _y.innerHTML = _x
  5. }
  6. Then, the parent page has a div with the id "framediv" which is placed where the contents of the iframe should appear on the page.
  7. The iframe element is then placed inside the div, like this:
  8.  
  9. <div id="framediv">
  10. <iframe onload="insertIt();" src="/somewhere/content.htm" frameborder="no" width="555px" scrolling="no">
  11. </div>

以上是关于使用javascript和div innerhtml调整iframe大小以匹配帧源的主要内容,如果未能解决你的问题,请参考以下文章

使用javascript播放声音剪辑[重复]

ajax跨域之jsonp

jsdate.getmonth怎么是两位数

vue 自定义js文件 写方法

使用javascript单击div内的x按钮动态添加和删除div [重复]

Javascript:使用切换按钮隐藏和显示 div 标签