我使用这种结构中的iframe其高度发送到父窗口:HTML 5 PostMessage的歌剧11.x的
<body onload="parent.postMessage(document.body.scrollHeight, '*');">
...
</body>
存在父窗口的监听器:
function resizeCrossDomainIframe(id)
{
var iframe = document.getElementById(id);
window.addEventListener('message', function (event)
{
if (isNaN(event.data)) return;
var height = parseInt(event.data);
iframe.height = height + "px";
}, false);
}
<iframe id="voice-iframe" scrolling="no" frameborder="0" onload="resizeCrossDomainIframe('voice-iframe');" src="http://localhost:2040/VoiceApi/Base">
</iframe>
此代码工作在ff,chrome,safari中,ie9,可能在ie8中,但不在歌剧11中(尽管蜻蜓中没有显示错误)。 我认为会有一些问题,但不是与最后版本的歌剧。 或者我正在做错误?
问题在于opera中的postmessage是文档的方法,而不是window的。 – donRumatta
这是不正确的(再) - 最初的实现是在文档上,但它已更改为window.postMessage()很久以前 – hallvors