【问题标题】:.click() giving access denied in IE11.click() 在 IE11 中拒绝访问
【发布时间】:2017-09-15 14:51:22
【问题描述】:

当尝试将anchor 标记的.click() 调用到auto click url 时。 该代码在除Internet Explorer v11 之外的所有浏览器中都能正常工作。

我们将不胜感激。

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 - jsfiddle.net/hcqn9m5a/3
  • 这里没有jQuery代码,为什么会有那个标签?

标签: javascript html internet-explorer


【解决方案1】:

对于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();
  }
}

【讨论】:

  • 所以对于 IE "var data = new Blob([HTML_APS]);"这将不起作用 应该实现此代码“navigator.msSaveOrOpenBlob(data, "report_html.htm")”?
  • 查看代码...var data = new Blob([HTML_APS]); 适用于所有浏览器...只是下载方式不同
【解决方案2】:

当使用下载属性锚点时,这表示浏览器应该下载锚点指向的资源,而不是导航到它。
它不支持 IE11。 供参考click here

【讨论】:

    【解决方案3】:

    根据this SO 的回答,“下载”属性尚未在 Internet Explorer 中实现。

    Internet Explorer 中没有实现下载属性。

    http://caniuse.com/download

    对于 Internet Explorer,您可以使用“另存为”命令。

    【讨论】:

      猜你喜欢
      • 2014-07-09
      • 1970-01-01
      • 2015-01-10
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 2014-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多