1

我正在按照教程(超过 300 票!)在Resizing an iframe based on content上根据内容的高度调整 iframe 的大小。

我的问题是我得到了 Uncaught TypeError: Object [object global] has no method 'ResizeIframe' in my helper.html。

想知道是否有人以前遵循过stackoverflow的答案并且也遇到过这个问题。

我的 helper.html:

<html> 
<h1>Helper</h1>
<!-- Testing small change. -->
<!-- 
This page is on the same domain as the parent, so can
communicate with it to order the iframe window resizing
to fit the content 
--> 
  <body onload="parentIframeResize()"> 
<script> 
// Tell the parent iframe what height the iframe needs to be
function parentIframeResize()
{
var height = getParam('height');
// This works as our parent's parent is on our domain..
parent.parent.resizeIframe(height);
}
// Helper function, parse param from request string
function getParam( name )
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
      return "";
    else
      return results[1];
  }
</script> 

我的 javascript 文件(在 iframe 嵌入的域上):

function resizeIframe(height)
{
// "+60" is a general rule of thumb to allow for differences in
// IE & and FF height reporting, can be adjusted as required..
if (document.getElementById('embedded-iframe')) {
document.getElementById('embedded-iframe').height = parseInt(height,10)+60;
}
}

同样,大部分代码都来自这个 stackoverflow 帖子:Resizing an iframe based on content

4

0 回答 0