我正在按照教程(超过300票!)来调整iframe的大小,根据Resizing an iframe based on content上内容的高度。
我的问题是我得到了Uncaught TypeError:对象[object global]在我的helper.html中没有'ResizeIframe'方法。
想知道是否有人之前已经遵循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。