.click()在IE11中拒绝访问
问题描述:
尝试调用anchor
标记的.click()
到auto click
url。 代码在所有浏览器中都正常工作,除了Internet Explorer
v11。.click()在IE11中拒绝访问
任何帮助将不胜感激。
var strContent = "a,b,c\n1,2,3\n";
var HTML_APS = strContent;
var data = new Blob([HTML_APS]);
var temp_link = document.createElement('a');
temp_link.href = URL.createObjectURL(data);
temp_link.download = "report_html.htm";
temp_link.type = "text/html";
temp_link.style = "display:none";
document.body.appendChild(temp_link);
if (confirm("Press a button!") == true) {
temp_link.click();
temp_link.remove();
}
这里是fiddle。
答
对于IE,你可以使用navigator.msSaveOrOpenBlob
因此,跨浏览器的代码将是
var strContent = "a,b,c\n1,2,3\n";
var HTML_APS = strContent;
var data = new Blob([HTML_APS]);
if (confirm("Press a button!") == true) {
if (navigator.msSaveOrOpenBlob) {
navigator.msSaveOrOpenBlob(data, "report_html.htm");
} else {
var temp_link = document.createElement('a');
temp_link.href = URL.createObjectURL(data);
temp_link.download = "report_html.htm";
temp_link.type = "text/html";
document.body.appendChild(temp_link);
temp_link.click();
temp_link.remove();
}
}
答
根据this SO答案,'下载'属性尚未在Internet Explorer中实现。
下载属性未在Internet Explorer中实现。
对于Internet Explorer,可以使用 “另存为” 命令。
的IE浏览器,使用'navigator.msSaveOrOpenBlob' - https://jsfiddle.net/ hcqn9m5a/3/ –
这里没有jQuery代码,为什么你有这个标签? – Barmar