Here is my 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>
Here ifr.contentDocument.body.style.cssText = (...) works fine on chrome but not on Firefox. Is it a firefox bug? Is there any workaround?
Found workaround: Looks like there is a weird race bug in firefox. The following workaround with setTimeout will make this work fine as shown below:
<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>