边缘浏览器 – iframe.document.open无法正常工作

我们有一些将数据导出到excel文件的function。 当点击“导出”button时,会调用一些客户端JavaScript,首先检查客户端浏览器版本,并在此基础上决定使用哪种方式呈现Excel文档。 在本地进行testing时,它正在使用Chrome&Firefox&IE11。 但是,当我使用运行Edge浏览器的Windows 10机器进行远程testing时,不会呈现excel。

我可能会补充说,我的本地机器是一个Win7的机器,我正在运行VS2012和IE11。 远程机器是带有Edge的Win10,因此需要远程testing。 我试过IE11 F12开发工具的仿真,但无法在那里复制Edge错误。

在使用以下代码时,“未定义或空引用”的错误引发为“打开”:

excelIFrame.document.open("txt/html", "replace"); excelIFrame.document.write(sHTML); excelIFrame.document.close(); excelIFrame.focus(); excelIFrame.document.execCommand("SaveAs", true, "Spreadsheet.xls"); 

iframe存在于html中,不会dynamic添加。

 <iframe id="excelIFrame" style="display:none"></iframe> 

我已经尝试了以下可能的解决scheme来获得这个工作,无济于事 –

可能的解决scheme1:将文档分配给临时variables时,相同的'未定义或空引用错误

 var doc = excelIFrame.document; doc.open("txt/html", "replace"); doc.write(sHTML); doc.close(); doc.focus(); doc.execCommand("SaveAs", true, "Spreadsheet.xls"); 

可能的解决scheme2:使用iFrame的contentWindow属性。 没有错误抛出,它只是打开“about:blank”不包含内容。

 excelIFrame.contentWindow.contents = sHTML; excelIFrame.src = 'javascript:window["contents"]'; 

这个阶段完全不知所措。 该页面是一个angularJS网页。 从阅读它,我知道document.open是有问题的边缘,当使用iframes。 但是下面的链接document.open在iframe中失败,我觉得会解决这个问题。 任何想法或build议不胜感激。