Edge浏览器- iframe.document.open不工作
Edge Browser - iframe.document.open not working
我们有一些将数据导出到excel文件的功能。当"导出"按钮被点击时,一些客户端javascript被调用,首先检查客户端浏览器版本,并以此为基础,决定以哪种方式呈现excel文档。它是在Chrome &火狐浏览器,本地测试时的IE11。但是,当我使用运行Edge浏览器的windows 10机器远程测试时,excel没有呈现。
我可能会补充说,我的本地机器是Win7机器,我运行VS2012和IE11。远程机器是带有Edge的Win10,因此需要进行远程测试。我已经在IE11 F12开发工具中尝试了仿真,但无法复制Edge错误。
使用以下代码时,'open'抛出'未定义或null引用'错误:
excelIFrame.document.open("txt/html", "replace");
excelIFrame.document.write(sHTML);
excelIFrame.document.close();
excelIFrame.focus();
excelIFrame.document.execCommand("SaveAs", true, "Spreadsheet.xls");
iframe存在于html中,不是动态添加的。
<iframe id="excelIFrame" style="display:none"></iframe>
我尝试了以下可能的解决方案来使其工作,但无济于事-
可能解决方案1:在将文档分配给临时变量时出现相同的"未定义或null引用错误"
var doc = excelIFrame.document;
doc.open("txt/html", "replace");
doc.write(sHTML);
doc.close();
doc.focus();
doc.execCommand("SaveAs", true, "Spreadsheet.xls");
方案2:使用iFrame的contentWindow属性。没有抛出错误,它只是打开'about:blank',不包含任何内容。
excelIFrame.contentWindow.contents = sHTML;
excelIFrame.src = 'javascript:window["contents"]';
在这个阶段完全不知所措。该页面是一个angularJS网页。通过阅读,我了解到这份文件。当使用iframes时,在边缘打开是有问题的。但下面的链接文档。open在一个我认为可以解决问题的框架中失败。如有任何意见或建议,不胜感激。
这可能对正在搜索它的其他人有帮助。
//For Edge browser ….. U have to write separate logic for each browser
if (ua.match(/Edge/)){
var blob = new Blob([sHTML], {type: 'data:application/vnd.ms-excel'});
window.navigator.msSaveBlob(blob, "P2P_Report_"+new Date().getTime()+".xls");
}
相关文章:
- Windows.Open 在 window.Location 工作时不起作用
- javascript window.open将无法在Chrome控制台上工作
- window.open尽管被用户触发,但仍无法在InternetExplorer中工作
- window.open没有't在设置setTimeout内工作-弹出窗口被阻止
- 使用window.open后,window.close无法在firefox中工作
- Javascript窗口.open不工作
- window.open无法在显示pdf的jsp页面中工作
- window.open在firefox上工作,而不是在chrome上
- window.open()没有'无法在添加到主屏幕的移动Safari web应用程序中工作
- 频道谷歌应用程序引擎频道.open()不工作
- window.open获胜'无法在Phonegap 1.7.0中工作
- Window.open不工作,布尔值不是函数
- window.open没有'我不在IE9上工作
- Window.Open无法从Phonegap的功能中工作
- jQuery 'prop' 在 FireFox 中无法在详细信息的 'open' 属性上工作
- window.open 在 iPad Safari 上无法按预期工作
- window.open没有'我不在http postangular工作
- Open在Firefox中不是一个函数,但它在Chrome中可以工作
- window.open在内联脚本中返回null并失败,但可以在控制台中工作
- window.open无法在IE 9、64位操作系统中工作