简体   繁体   English

在Firefox中触发点击事件

[英]Triggering a click event in firefox

My requirement is to import a html table to a CSV file. 我的要求是将html表导入CSV文件。 The code below gets called when the Download to CSV button is clicked in my web page. 在我的网页中单击“下载到CSV”按钮时,将调用以下代码。 This works fine in chrome however in firefox it does nothing. 这在chrome中效果很好,但是在Firefox中却什么也没做。

input.addEventListener('click', function (e) {
    var fileName = cntrySel.value + '-Data.csv';
    var a = document.createElement('a');
    var data=$('#output').table2CSV({delivery:'value'});
    blob = new Blob([data], { type: 'text/csv' }); //new way
    var csvUrl = URL.createObjectURL(blob);
    a.download = fileName;
    a.href = csvUrl;
    a.click();
    a.setAttribute('onClick','');
    e.preventDefault();
  });

In firefox debugger, I can see the above function is getting triggered upon click but a.click() does nothing in FF whereas it downloads the csv file in chrome. 在firefox调试器中,我可以看到上述功能在单击时被触发,但是a.click()在FF中什么也不做,而它以chrome下载csv文件。

Any help is appreciated. 任何帮助表示赞赏。

Soon after I posted this question, I came across this link Dynamically created ahref click event not working in firefox or safari? 发布此问题后不久,我遇到了此链接动态创建的ahref点击事件在Firefox或Safari浏览器中不起作用? which has the answer. 有答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM