.click()在IE11中拒绝访问 [英] .click() giving access denied in IE11

查看:783
本文介绍了.click()在IE11中拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试将标记的 .click()调用到 auto时点击网址。
代码在所有浏览器中都运行良好,除了 Internet Explorer v11

When trying to invoke a .click() of an anchor tag to auto click the url. The code is working fine in all browsers except 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();
}

这里是小提琴

推荐答案

对于IE,您可以使用 navigator.msSaveOrOpenBlob

For IE, you can use navigator.msSaveOrOpenBlob

所以,跨浏览器,代码将是

so, cross browser, the code would be

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

这篇关于.click()在IE11中拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆