2010-06-04 33 views
2

這個工作在IE瀏覽器,但在Firefox這是很奇怪:的iFrame的designMode在Firefox問題

如果打開它通常如果Firefox時,將designMode不工作,但如果我把一個斷點

this.editor.contentWindow.document.designMode =「On」;

行,然後釋放它(它打破之後),設計模式工作!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
     <title>Untitled Document</title> 
     <script type="text/javascript"> 



TheEditor = function() { 
    this.editor = null; 
    this.mainDiv=document.getElementById("mainDiv"); 
} 

TheEditor.prototype = { 

     InitializeEditor: function() { 


     this.editor=document.createElement('iframe'); 
     this.editor.frameBorder=1; 
     this.editor.width = "500px"; 
     this.editor.height="250px";  

     this.mainDiv.appendChild(this.editor); 

     this.editor.contentWindow.document.designMode = "On";  
    }  


} 
      window.onload = function(){ 
       obj = new TheEditor; 
       obj. InitializeEditor(); 
      } 
     </script> 
    </head> 
    <body> 
     <div id="mainDiv"> 
    </div> 
    </body> 
</html> 

回答

0

我不完全明白爲什麼,但開口(可選寫的內容),並關閉文檔解決問題(至少在FF5上OSX):

this.editor.contentWindow.document.open(); 
// optionally write content here 
this.editor.contentWindow.document.close(); 
this.editor.contentWindow.document.designMode = "on"; 

其他的想法,我有是要在designMode = "on"聲明(我記得在過去爲FF做這個事情)的時候設置一個超時時間,但它不起作用。

我認爲它與FF加載IFRAME中的「東西」有關,它沒有準備好打開designMode。

我想你也可以使用DIV上的contentEditable="true"屬性。

無論如何,我希望這會有所幫助。

0

我認爲這是因爲contentDocument尚未創建,我認爲您也可以設置iframe的onload事件並在此事件中設置設計模式,因爲在加載頁面時會調用此事件,因此contentDocument存在!