IE8 在 JavaScript 弹出窗口上奇怪地崩溃

创建弹出窗口后,我遇到了一个奇怪的问题onclick.弹出窗口打开但在 IE8 上立即挂起(在包括 IE6 在内的所有其他浏览器上都可以正常工作).但是在添加 alert 框时,如 JavaScript 代码所示,弹出窗口工作正常.

I am facing a strange issue after the popup is created onclick. The popup opens up but hangs immediately on IE8 (works fine on all the other browsers including IE6). But on adding the alertbox as show in the JavaScript code, the popup works fine.

我使用的是 **https** 而不是 **http**,我觉得弹出窗口无法加载 JS 文件,因为 SSL.

I am using **https** and not **http** and i feel popup is not able to load the JS file because of SSL.

这是我生成 onclick 事件的方式:

Here is the how i am generating the onclick event:

<a id="forgotPasswordLink" href="#" onclick="openSupportPage();"> Some Text </a>

onclick 函数是这样定义的:

        function openSupportPage() {
            var features = "width=700,height=400,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";
            var winId = window.open('', '', features);
            winId.focus();
            winId.document.open();
            winId.document.write('<html><head><title>' + document.title + '</title><link rel="stylesheet" href="./css/default.css" type="text/css">
');
            var is_ie6 = (
            window.external && typeof window.XMLHttpRequest == "undefined");
            alert(is_ie6);/*The JS include below*/
                          /*works in popup only with this alert box.*/
                          /*else IE8 Hangs*/
                winId.document.write('<script src="../js/tiny_mce/tiny_mce.js" type="text/javascript">Script_IE8</script>
');


            winId.document.write('<script type="text/javascript">
');
            winId.document.write('function inittextarea() {
');
            winId.document.write('tinyMCE.init({  
');
            winId.document.write('elements : "content",
');
            winId.document.write('theme : "advanced",
');
            winId.document.write('readonly : true,
');
            winId.document.write('mode : "exact",
');
            winId.document.write('theme : "advanced",
');
            winId.document.write('readonly : true,
');
            winId.document.write('setup : function(ed) {
');
            winId.document.write('ed.onInit.add(function() {
');
     winId.document.write('tinyMCE.activeEditor.execCommand("mceToggleVisualAid");
');
            winId.document.write('});
');
            winId.document.write('}
');
            winId.document.write('});}</script>
');
            winId.document.write('</head><body onload="inittextarea()">
');
            winId.document.write('  
');
            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%">
');
            winId.document.write(document.getElementById(top.document.forms[0].id + ":supportStuff").innerHTML);
            winId.document.write('</textArea>
');
            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>
');
            winId.document.close();
    }

请帮我解决这个问题.如果需要,我可以提供更多信息.

Please help me on this one. I could provide more information on this if needed.

我参考了这些帖子已经:

I have referred to these posts already:

  • 使用http URL在https页面中导入js文件在 IE8 中
  • 强制浏览器模式=IE8和文档模式=IE8标准

其他信息:

  • 页面截图
  • 呈现的 HTML
  • 原始 JSPF

推荐答案

这是解决我的问题的最终工作功能,适用于 IE6、IE7、IE8、Chrome、Firefox、Safari 和 Opera.

Here is the final working function which solved my issue and works in IE6, IE7, IE8, Chrome, Firefox, Safari and Opera.

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">
');

    window.setTimeout(function () {
        winId.document.write(
          '<script src="../js/tiny_mce/tiny_mce.js" type="text/javascript"></scr' + 'ipt>
'
        );
    }, 10);

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

    window.setTimeout(function () {
        winId.document.write('</head><body onload="inittextarea()">
');
        winId.document.write('  
');
        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%">
');
        winId.document.write(document.getElementById(top.document.forms[0].id + ":supportStuff").innerHTML);
        winId.document.write('</textArea>
');
        var hiddenFrameHTML2 = document.getElementById("HiddenFrame2").innerHTML;
        hiddenFrameHTML2 = hiddenFrameHTML2.replace(/&amp;/gi, "&");
        hiddenFrameHTML2 = hiddenFrameHTML2.replace(/&lt;/gi, "<");
        hiddenFrameHTML2 = hiddenFrameHTML2.replace(/&gt;/gi, ">");
        //hiddenFrameHTML2 = hiddenFrameHTML2.replace(/&amp;/gi, "&").replace(/&lt;/gi, "<").replace(/&gt;/gi, ">");
        winId.document.write(hiddenFrameHTML2); 
        winId.document.write('</body></html>
');
        winId.document.close();
    }, 300);
}

我从这些问题中得到了很多帮助:

I got a lot of help from these questions:

  • 格式化此 JavaScript 行
  • JavaScript 源文件未在 IE8 弹出窗口中加载

谢谢大家.

相关文章