2013-02-23 49 views
1

我已經寫了一個javascript函數來創建簡單的內容iframe,其工作正常在所有瀏覽器IE9,8,7和鉻,但不工作在Mozilla Firefox中,什麼是我的代碼問題?即使在控制檯中沒有任何異常。動態創建的內容在Firefox中的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 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> 
+0

是否禁用了所有插件,看是否其中一人被阻止內容? – Zefiryn 2013-02-23 07:14:55

+0

哪種插件?火狐插件? – 2013-02-23 07:19:17

+0

是的,嘗試暫時停用所有插件並檢查頁面是否正常工作。如果是這樣,請逐個打開它們以找出哪一個導致問題。 – Zefiryn 2013-02-23 11:40:03

回答

1

我發現我的答案

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); 
    }