我已经使用document.createElement('a')
方法创建了一个锚元素,但是在尝试触发click事件时,它不会触发click事件。有关更多详细信息,请参见以下代码
var link = document.createElement("a");
link.setAttribute("href", context+"/images/"+filePath);
link.setAttribute("href", "http://192.168.0.170:8082/abc/AttachmentData/getAttachment?path=pathTofile");
link.setAttribute("download", "abc.csv");
link.click();
我想下载文件。href中提供了文件链接。该代码在我的本地系统上有效,但是在生产服务器上部署时不起作用。
您刚刚创建了link元素,但尚未将其添加到文档中。
尝试:
document.body.appendChild(link); // put it where you want the link show.
link.click()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句