firefox中动态创建的内容iframe问题
Dynamic created content iframe issue in firefox
我已经编写了一个javascript函数来创建简单的内容iframe,它在所有浏览器IE9、8、7和chrome中都能正常工作,但在mozilla firefox中却不能工作,我的代码有什么问题?甚至在控制台中没有得到任何异常。
function (parent, child, cssfile, jsfilepath) {
var iframe = document.createElement('iframe');
iframe.id = ('MyID' + Math.floor((Math.random() * 1000000000000000000) + 1));
iframe.frameBorder = '0';
iframe.scrolling = 'no';
iframe.marginWidth = '0';
iframe.marginHeight = '0';
iframe.hspace = '0';
iframe.vspace = '0';
iframe.allowTransparency = "true";
parent.appendChild(iframe);
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
var inter = window.setInterval(function() {
if(iframeDoc.readyState == "complete") {
window.clearInterval(inter);
iframeDoc.body.innerHTML = child;
iframeDoc.body.style.background = "transparent";
addExternalCss(cssfile, iframeDoc);
addEmbedCss('body {margin:0px; padding:0px;}', iframeDoc);
addJs(jsfilepath, iframeDoc);
}
},100);
}
编辑
只是在firebug 中显示空白iframe
<iframe scrolling="no" frameborder="0" id="MyId350236077714409500" marginwidth="0" marginheight="0">
<html><head></head><body></body></html>
</iframe>
我找到了我的答案
function (parent, child, cssfile, jsfilepath) {
var iframe = document.createElement('iframe');
iframe.id = ('MyID' + Math.floor((Math.random() * 1000000000000000000) + 1));
iframe.frameBorder = '0';
iframe.scrolling = 'no';
iframe.marginWidth = '0';
iframe.marginHeight = '0';
iframe.hspace = '0';
iframe.vspace = '0';
iframe.allowTransparency = "true";
parent.appendChild(iframe);
var inter = window.setInterval(function() {
// put inside function
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
if(iframeDoc.readyState == "complete") {
window.clearInterval(inter);
iframeDoc.body.innerHTML = child;
iframeDoc.body.style.background = "transparent";
addExternalCss(cssfile, iframeDoc);
addEmbedCss('body {margin:0px; padding:0px;}', iframeDoc);
addJs(jsfilepath, iframeDoc);
}
},100);
}
相关文章:
- 由于iframe导致的问题
- 使用YouTube iFrame API的IE中的JavaScript问题
- 将HTML表单发布到iframe会导致浏览器历史记录出现问题
- 从父页面调用iframe中的javascript,IE问题
- 在Google Chrome中打印iFrame时出现问题
- 在Internet Explorer 8中的Iframe中创建TinyMCE时出现问题
- 这个基于iFrame选择器的if函数有什么问题
- 当内容显示在FireFox的iFrame中时,jQuery高度问题
- 如何应对iframe安全问题
- 使用 Iframe 问题设置跨域 Cookie
- 代码镜像和 iFrame 问题
- IPhone的webview和iframe问题
- jQuery表单插件-iframe问题
- Firefox flash wmode=不透明iframe问题
- firefox中动态创建的内容iframe问题
- CGridView分页-Yii框架中的IFrame问题
- 简单的iframe问题
- 火狐 iframe 问题
- 网页抓取 - 无法使用Javascript和WebView单击HTML输入按钮(可能是iframe问题,不确定)
- JQuery插件IFrame问题