2010-06-01 64 views
1

我有一個JavaScript源文件在IE6,Chrome,Firefox,Safari和Opera的彈出窗口中加載的問題。但是相同的源文件在IE8中沒有加載。在IE8彈出窗口中未加載JavaScript源文件

由於這個HTML is not being replaced in the Popup的結果,我得到一個錯誤在IE8彈出說tinyMCE is not defined

我都提到Formatting this JavaScript Line和解決上,除了IE8瀏覽器的所有問題。

JavaScript函數如下:

function openSupportPage() { 
    var features="width=700,height=400,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";    
    var winId=window.open('','',features); 
    winId.document.open(); 
    winId.document.write('<html><head><title>' + document.title + '</title><link rel="stylesheet" href="../css/default.css" type="text/css">\n'); 

    var winDoc = winId.document; 
    var sEl = winDoc.createElement("script"); 
    sEl.src = "../js/tiny_mce/tiny_mce.js";/*TinyMCE source file*/ 
    sEl.type="text/javascript"; 
    winDoc.getElementsByTagName("head")[0].appendChild(sEl); 

    winId.document.write('<script type="text/javascript">\n'); 
    winId.document.write('function inittextarea() {\n'); 
    winId.document.write('tinyMCE.init({ \n'); 
    winId.document.write('elements : "content",\n'); 
    winId.document.write('theme : "advanced",\n'); 
    winId.document.write('readonly : true,\n'); 
    winId.document.write('mode : "exact",\n'); 
    winId.document.write('theme : "advanced",\n'); 
    winId.document.write('readonly : true,\n'); 
    winId.document.write('setup : function(ed) {\n'); 
    winId.document.write('ed.onInit.add(function() {\n'); 
    winId.document.write('tinyMCE.activeEditor.execCommand("mceToggleVisualAid");\n'); 
    winId.document.write('});\n'); 
    winId.document.write('}\n'); 
    winId.document.write('});}</script>\n'); 

    window.setTimeout(function() {/*using setTimeout to wait for the JS source file to load*/ 
     winId.document.write('</head><body onload="inittextarea()">\n'); 
     winId.document.write(' \n'); 
     var hiddenFrameHTML = document.getElementById("HiddenFrame").innerHTML; 
     hiddenFrameHTML = hiddenFrameHTML.replace(/&amp;/gi, "&"); 
     hiddenFrameHTML = hiddenFrameHTML.replace(/&lt;/gi, "<"); 
     hiddenFrameHTML = hiddenFrameHTML.replace(/&gt;/gi, ">"); 
     winId.document.write(hiddenFrameHTML); 
     winId.document.write('<textarea id="content" rows="10" style="width:100%">\n'); 
     winId.document.write(document.getElementById(top.document.forms[0].id + ":supportStuff").innerHTML); 
     winId.document.write('</textArea>\n'); 
     var hiddenFrameHTML2 = document.getElementById("HiddenFrame2").innerHTML; 
     hiddenFrameHTML2 = hiddenFrameHTML2.replace(/&amp;/gi, "&"); 
     hiddenFrameHTML2 = hiddenFrameHTML2.replace(/&lt;/gi, "<"); 
     hiddenFrameHTML2 = hiddenFrameHTML2.replace(/&gt;/gi, ">"); 
     winId.document.write(hiddenFrameHTML2); 
     winId.document.write('</body></html>\n'); 
     winId.document.close(); 
    }, 300); 
} 

附加信息

請幫助我這個。

回答

1
  1. 你爲什麼要使用實際的DOM功能添加<script>標記,包括tinymce.js但一切是使用document.write?

  2. 我認爲這也是你的問題所在,因爲<head><html>之內,它還沒有關閉,你想要追加所說的<script>標籤。

  3. 否則,您可以使用彈出窗口中現有的<script>標籤添加包含所需外部JavaScript文件的代碼。如果那有意義的話。

所以,基本上我說的是,使用document.write以與其他所有內容相同的方式嘗試。

(快速添加)我不是說這是做這件事的'最佳'方法,我會建議創建一個實際頁面,而不是在彈出窗口中動態創建一個。但在這種情況下,我認爲我之前寫的可能會解決您遇到的問題。

+0

我正在嘗試選項!非常感謝。你的回答幫助了我。 – dkris 2010-06-01 14:28:39

+0

@dkris:你究竟做了什麼來解決這個問題? – 2010-11-21 21:35:21

+0

@Srini我最終這樣做[http://stackoverflow.com/questions/2943965/ie8-crashes-strangely-on-javascript-popup] – dkris 2010-12-13 05:32:28