我的主页可以发送参数到IFrame并显示它。我使用了一个简单的(跨浏览器的)方法,在这个页面中被描述为'Frames Array'。
但是它在FF, Chrome, IE和Safari中工作得很好,但在Opera中不行。
IFrame:
var iframe = document.createElement('iframe');
iframe.src = 'Layout.error.htm';
iframe.name = 'error';
iframe.id = 'error'; // this is necessary for IE
iframe.style.cssText = "height: 150px; width: 300px";
document.body.appendChild(iframe);
window.frames['error'].data = 'xx';
和IFrame主体:
<script>
alert(data);
</script>
Opera提示"未处理错误:未定义变量:data";(IFrame脚本)…
数据可以在IFrame脚本被触发后发送,所以我尝试添加一个'Update'函数:
window.frames['error'].data = 'xx';
window.frames['error'].Update();
_____
<script>
function Update ()
{
alert ('data');
}
</script>
未处理错误:'window.frames[' Error '].Update'不是一个函数';(主页脚本,即使我已经清除缓存)…
这个浏览器有什么问题
因此,由于Opera12,一旦iFrame完全加载,必须从父页面控制iFrame。这可以通过回调来实现:
<!-- callback into the iframe-->
<script type="text/javascript"> window.top.window.callback(); </script>
父:function callback() {
var iframe = window.frames['name'];
var innerDoc = iframe.document;
// handle the content ..
}
var iframe = document.createElement('iframe');
iframe.src = ...;
iframe.name = 'name';
iframe.id = 'name';
document.body.appendChild(iframe);