[英]Firefox dynamically generated link clicking
I have logic, what when users clicks "download" button, it makes http request to rest api, and then by response browser or starts download, or writes user a message what download cannot be started, code looks like this 我有逻辑,当用户单击“下载”按钮时,它将发出http请求以请求api,然后通过响应浏览器或开始下载,或者向用户发送消息,提示无法开始下载,代码如下所示
if (file.is_active) {
var link = document.createElement('a');
link.href = filesUri + file.path;
link.title = 'filedownload';
link.setAttribute('download', file.body);
link.click();
} else {
// error message
}
and this code works perfectly in safari/chrome, but it doesn't in firefox, is there any possibilities to bypass this check? 并且此代码在safari / chrome中可以完美运行,但在Firefox中不可用,是否有可能绕过此检查?
Firefox probably prevents downloading without user interaction. Firefox可能会在没有用户交互的情况下阻止下载。
You should put your button inside a tag, set listener to button and before event delegates to link change a attributes to download correct file. 你应该把一个标签内的按钮,设置监听器按钮和属性下载正确的文件之前,事件委托链接变化 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.