动态创建的ahref点击事件在Firefox或Safari浏览器中不起作用? [英] Dynamically created ahref click event not working in firefox or safari?
本文介绍了动态创建的ahref点击事件在Firefox或Safari浏览器中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用javascript动态创建ahref标签,以下载使用javascript代码生成的csv文件.以下代码在chrome中可以正常工作,但在safari或Firefox中不起作用...
i am creating ahref tag dynamically using javascript to download csv file generated using javascript code. The following code is working fine in chrome but doesn't work in safari or firefox...
var a = document.createElement('a');
var blob = new Blob([str], {'type':'application\/octet-stream'});
a.href = window.URL.createObjectURL(blob);
a.download = 'export.csv';
a.click();
非常感谢您的帮助.
推荐答案
要使其在Firefox中运行,只需将新元素插入DOM(apendChild
等).
To make it work in Firefox, just insert the new element into the DOM (apendChild
, etc).
我认为这不适用于Safari:
I don't think this will work in Safari:
-
不支持
-
<a download="">
(正确),AFIAK.例如.a.download =
不会做您想要的.您仍然可以使用setAttribute
,但是Safari仍然会忽略它. - 我认为Safari确实不支持下载blob:-URI.
<a download="">
isn't (properly) supported yet, AFAIK. E.g.a.download =
will not do what you want. You could still usesetAttribute
but Safari will still ignore it.- I don't think Safari does support downloading of blob:-URIs, anyway.
这篇关于动态创建的ahref点击事件在Firefox或Safari浏览器中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文