Resizing an iframe based on contentのコンテンツの高さに応じて iframe のサイズを変更するには、チュートリアル (300 票以上!) に従っています。
私の問題は、「Uncaught TypeError: Object [object global] has no method 'ResizeIframe' in my helper.html.
誰かが以前にスタックオーバーフローの回答に従っていて、この問題にも遭遇したことがあるかどうか疑問に思っています。
私の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;
}
}
繰り返しますが、ほとんどのコードは、このスタック オーバーフローの投稿からのものです: Resizing an iframe based on content .