导出文件在 IE 11 中不起作用
Export file does not work in IE 11
我正在尝试导出一个 Excel 文件,到目前为止它确实适用于 IE 11 以外的浏览器。以下是我的代码:
if (navigator.appName == "Microsoft Internet Explorer") {
myFrame.document.open("text/html", "replace");
myFrame.document.write(data);
myFrame.document.close();
myFrame.focus();
myFrame.document.execCommand('SaveAs', true, fileName);
} else {
var blobdata = new Blob(data], { type: 'data:application/vnd.ms-excel' });
var link = document.createElement("a");
link.setAttribute("href", window.URL.createObjectURL(blobdata));
link.setAttribute("download", fileName);
document.body.appendChild(link);
link.click();
}
IE 11 中没有错误消息,只是什么也没发生。它适用于 IE < 11。
谢谢,
我认为 navigator.appname 不是你想要的,
来自:http://www.w3schools.com/jsref/prop_nav_appname.asp
returned 值因浏览器而异:
IE11、Firefox、Chrome 和 Safari returns "Netscape"
IE 10 及更早版本 return "Microsoft Internet Explorer"
歌剧 returns "Opera"
您可以考虑使用 navigator.userAgent
并确保您正确解析字符串。
我正在尝试导出一个 Excel 文件,到目前为止它确实适用于 IE 11 以外的浏览器。以下是我的代码:
if (navigator.appName == "Microsoft Internet Explorer") {
myFrame.document.open("text/html", "replace");
myFrame.document.write(data);
myFrame.document.close();
myFrame.focus();
myFrame.document.execCommand('SaveAs', true, fileName);
} else {
var blobdata = new Blob(data], { type: 'data:application/vnd.ms-excel' });
var link = document.createElement("a");
link.setAttribute("href", window.URL.createObjectURL(blobdata));
link.setAttribute("download", fileName);
document.body.appendChild(link);
link.click();
}
IE 11 中没有错误消息,只是什么也没发生。它适用于 IE < 11。
谢谢,
我认为 navigator.appname 不是你想要的, 来自:http://www.w3schools.com/jsref/prop_nav_appname.asp returned 值因浏览器而异: IE11、Firefox、Chrome 和 Safari returns "Netscape" IE 10 及更早版本 return "Microsoft Internet Explorer" 歌剧 returns "Opera"
您可以考虑使用 navigator.userAgent 并确保您正确解析字符串。