在firefox中使用URL下载文件无法在Angular JS中使用 [英] Download file using URL in firefox not working in angular JS

查看:104
本文介绍了在firefox中使用URL下载文件无法在Angular JS中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码在提供下载功能的google chrome中工作,并在firefox中始终显示在新标签或selftab中,就像在firefox中打开XML文件一样,我该如何下载呢? 因此,为我提供一些建议,以用于Firefox的角度JS或Java脚本下载功能! 这是我尝试过的代码

My code works in google chrome that provide download and in firefox it always show in new tab or selftab like XML file open in firefox how should I can download it? So provide me some suggestion to download functionality in angular JS or Java script for Firefox! This is my code which I tried

var link = document.createElement('a');
link.setAttribute('href', url);
link.setAttribute('download', filename);

推荐答案

创建的锚标记也需要添加到Firefox中的DOM中,以便被click事件识别.

The anchor tag you are creating also needs to be added to the DOM in Firefox, in order to be recognized for click events.

document.body.appendChild(link);
link.click();

这篇关于在firefox中使用URL下载文件无法在Angular JS中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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