【发布时间】:2013-04-29 04:46:53
【问题描述】:
这是我的 testing.html:
<html>
<meta charset="utf-8">
<script>
window.onload = function() {
var a = document.getElementById("divid");
var ifr = document.createElement('iframe');
a.appendChild(ifr);
ifr.contentDocument.body.style.cssText = (
'margin: 0px;' +
'padding: 0px;' +
'height: 100%;' +
'width: 100%;');
}
</script>
<head></head>
<body>
<div id="divid"/>
</body>
</html>
这里 ifr.contentDocument.body.style.cssText = (...) 在 chrome 上可以正常工作,但在 Firefox 上不行。它是Firefox的错误吗?有什么解决办法吗?
找到解决方法: 看起来Firefox中有一个奇怪的种族错误。使用 setTimeout 的以下解决方法将使其正常工作,如下所示:
<html>
<meta charset="utf-8">
<script>
window.onload = function() {
var a = document.getElementById("divid");
var ifr = document.createElement('iframe');
ifr.id = "fid";
a.appendChild(ifr);
setTimeout (function() {
ifr.contentDocument.body.style.cssText = (
'margin: 0px;' +
'padding: 0px;' +
'height: 100%;' +
'width: 100%;');
}, 100);
}
</script>
<head></head>
<body>
<div id="divid"/>
</body>
</html>
【问题讨论】:
-
这正是您所需要的:stackoverflow.com/questions/926916/…
标签: javascript html google-chrome firefox iframe