我遇到一个问题,即在 IE6、Chrome、Firefox、Safari 和 Opera 的弹出窗口中加载 JavaScript 源文件。但相同的源文件在 IE8 中无法加载。
因此 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(/&/gi, "&");
hiddenFrameHTML = hiddenFrameHTML.replace(/</gi, "<");
hiddenFrameHTML = hiddenFrameHTML.replace(/>/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(/&/gi, "&");
hiddenFrameHTML2 = hiddenFrameHTML2.replace(/</gi, "<");
hiddenFrameHTML2 = hiddenFrameHTML2.replace(/>/gi, ">");
winId.document.write(hiddenFrameHTML2);
winId.document.write('</body></html>\n');
winId.document.close();
}, 300);
}
Additional Information:
请帮我解决这个问题。
最佳答案
为什么使用实际的 DOM 函数来添加
<script>
包含tinymce.js 的标签,但其他所有内容都使用document.write?我认为这也是你的问题所在,如
<head>
在<html>
内,它尚未关闭,您想要在其中附加所述<script>
标签。否则,您可以使用现有的
<script>
弹出窗口中的标记以添加包含所需外部 javascript 文件的代码。如果这有任何意义的话。
所以,基本上我是说,像脚本中的其他内容一样尝试它,使用 document.write
.
(快速添加)我并不是说这是执行此操作的“最佳”方法,我建议创建一个实际页面,而不是在弹出窗口中动态创建页面。但在这种情况下,我认为我之前写的内容可能会解决您遇到的问题。
关于JavaScript 源文件未在 IE8 弹出窗口中加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2950405/