gpt4 book ai didi

javascript - 为什么我的 iframe 不调整大小以适合其内容?

转载 作者:行者123 更新时间:2023-11-28 15:35:47 25 4
gpt4 key购买 nike

我正在按照说明 here 尝试跨站点 iframe 调整大小,但 iframe 保持未调整大小。我不确定我做错了什么。

iframe 当前位于 http://ayeoui.com/testerpage.php .这会调用博客文章,该文章会在 ayeoui.c​​om 主域上加载一个“helper.html”页面,理论上应该将信息传递回第一页并触发调整大小。主站点上的代码是这样说的:

<script>
// Resize iframe to full height
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..
document.getElementById('iframeid').height = parseInt(height)+60;
}
</script>
<iframe id='iframeid' src='http://rinich.com/blog/11/index.html'></iframe>

链接页面上依次写有这段代码:

<body onload="iframeResizePipe()">
<iframe id="helpframe" src='' height='0' width='0' frameborder='0'></iframe>

<script type="text/javascript">
function iframeResizePipe()
{
// What's the page height?
var height = document.body.scrollHeight;

// Going to 'pipe' the data to the parent through the helpframe..
var pipe = document.getElementById('helpframe');

// Cachebuster a precaution here to stop browser caching interfering
pipe.src = 'http://www.ayeoui.com/helper.html?height='+height+'&cacheb='+Math.random();

}
</script>

最后,这将我们带到帮助页面:

<html> 
<!--
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>
</body>
</html>

然而,测试页面没有任何变化!显然我做错了什么,但我不确定是什么。发生了什么事?

最佳答案

未捕获的安全错误:阻止来源为“http://www.ayeoui.c​​om”的框架访问来源为“http://ayeoui.c​​om”的框架。协议(protocol)、域和端口必须匹配。

您的子域不匹配。 http://www.ayeoui.c​​omhttp://ayeoui.c​​om完全不同。

关于javascript - 为什么我的 iframe 不调整大小以适合其内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12514903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com