document.close()函数导致ie10兼容模式失败

时间:2013-07-31 13:14:18

标签: javascript internet-explorer-10 mode

我正在使用以下函数openwin()来编写页面并打开它。 问题是如果我使用myWindow.document.close();使用IE10兼容模式时失败 崩溃报告称“远程过程调用失败”,指的是document.close()。

如果我单步执行调试器,它不会失败(可能是它在某处自动关闭文档)。

如果我不关闭文档(在任何IE模式下)页面在加载javascript(谷歌翻译)之前等待大约30秒。大概是页面超时并自行关闭文档然后运行javascript。

任何想法导致这种情况(IE10兼容模式失败)?

此外 - 仅当页面包含脚本时才会出现此问题。

谢谢,

Fergal。

function openWin(){
    if( $('#worksheetbtn').data('created')==true){
        var day = new Date(); 
        var id = day.getTime();
        myWindow=window.open("",id);
        myWindow.document.write('<html><head>');
        myWindow.document.write('<meta name="google-translate-customization" content="8920959a5c7c1a2e-252a0ea397b87b27-g0d7aa06f124f9dec-14"></meta>');
        myWindow.document.write('<style type="text/css"> td {valign="top";} td.upper_line { border-top:solid 1px ;}table.fraction {border-top-color: #000000;text-align: center; vertical-align: middle; margin-top:0.5em; margin-bottom:0.5em; line-height: 2em; }</style> ');
        myWindow.document.write('<title> Steps To Maths Worksheet Creator - STM The software for Learning Maths Online. </title>');
        myWindow.document.write('</head>    <body>');
        myWindow.document.write('<div id="google_translate_element">Translate</div>');
        myWindow.document.write('<p>Steps To Maths </p>'    );
        myWindow.document.write($('#worksheetbtn').data('worksheet_html') );
        myWindow.document.write('</body>');
        myWindow.document.write('<script type="text/javascript"> function googleTranslateElementInit() {  new google.translate.TranslateElement({pageLanguage: \'en\', autoDisplay: false}, \'google_translate_element\');}</script>');
        myWindow.document.write('<script type="text/javascript" src="\/\/translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>');


        myWindow.document.write('</html>');
        myWindow.focus();
//      myWindow.document.close(); 

    } else alert('The worksheet cannot be opened, please select a category, number of questions and click on the Load Questions button');
}

1 个答案:

答案 0 :(得分:-1)

你可以使用

myWindow.close();
相关问题