admin管理员组文章数量:1287831
I was stuck here not understood go further. some screens works same code but some not.
var element = document.createElement('a');
element.setAttribute('href', 'data:text/html;charset=utf-8,' + encodeURIComponent(strOutput.replaceAll('£', '£')));
element.setAttribute('download',"fpversions");
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
can anyone help me.
I was stuck here not understood go further. some screens works same code but some not.
var element = document.createElement('a');
element.setAttribute('href', 'data:text/html;charset=utf-8,' + encodeURIComponent(strOutput.replaceAll('£', '£')));
element.setAttribute('download',"fpversions");
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
can anyone help me.
Share Improve this question asked Jun 3, 2022 at 13:18 rama raorama rao 811 gold badge1 silver badge7 bronze badges 1- Does this answer your question? How to download file with javascript? – Besworks Commented Jun 3, 2022 at 18:48
2 Answers
Reset to default 8this is a sample javascript code on how to download files via javascript
var textToSave = 'this is a test';
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:attachment/text,' + encodeURI(textToSave);
hiddenElement.target = '_blank';
hiddenElement.download = 'myFile.txt';
hiddenElement.click();
function myFunction() {
var textToSave = 'this is a test';
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:attachment/text,' + encodeURI(textToSave);
hiddenElement.target = '_blank';
hiddenElement.download = 'myFile.txt';
hiddenElement.click();
}
<button onclick="myFunction()">Click me</button>
in my case using the idea of robin i put the next code for a url in base64
let url1 = data:application/pdf;base64, ${response.data.c_planilla[0].PLANILLA}
var hiddenElement = document.createElement('a');
hiddenElement.href = url1;
hiddenElement.target = '_blank';
hiddenElement.download = 'Planilla ARI.pdf';
hiddenElement.click();
本文标签: htmlHow to generate a download file in javascriptStack Overflow
版权声明:本文标题:html - How to generate a download file in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741322124a2372263.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论