页面中加载iframe的常见问题总结

1、页面引用ifram

<iframe src="URL" id="iframe" name="iframe" frameborder="0" marginwidth="0" align="left"  height="550px" width="100%" scrolling="auto" marginheight="0"
    onload="setIframeHeight()">
</iframe>

 

2、高度自适应,避免出现滚动条

 

/** iframe高度自适应 **/
function setIframeHeight() {
  var iframe =  document.getElementById("iframe");
  if (iframe) {
    var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
    if (iframeWin.document.body) {
      iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
    }
  }
}
/** 改变页面大小是触发 **/
window.onresize=function(){
  setIframeHeight();
}

 

 

3、父页面获取iframe对象

var iframe = window.frames["iframe"];
var xxx = iframe.document.getElementById("xxx").value;

 

4、ifame获取父页面对象

var parWin = parent.window;

 

posted @ 2017-09-28 11:36  柒陆零柒伍伍柒玖零  阅读(2117)  评论(0编辑  收藏  举报