How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Javascript to Download String Ask Question.
Asked 7 years, 9 months ago. Active 7 years, 6 months ago. Viewed 15k times. I know if it were a file, the following would do it: window. Joe Bergevin Joe Bergevin 2, 4 4 gold badges 25 25 silver badges 33 33 bronze badges. I see: stackoverflow. Add a comment. Active Oldest Votes.
The download attribute was added to the anchor element in HTML 5. It informs the browser to download the requested URL instead of navigating to it. You can also specify an optional value for the download attribute to be used as a file name once it is downloaded. If the value is not provided, the original filename is used.
As you can see above, the download attribute is the easiest way to download a file on the browser. However, the download attribute only works in modern browsers. Internet Explorer does not support it. The idea is to programmatically create an anchor link, and then trigger the click event. This method is especially helpful for dynamically generated file URLs. This will help us to replace certain special characters with a combination of escape sequences.
Append this created element to the body of the document HTML page. Use element. Remove the element from the body of the document HTML page. Attach this link to the document and simulate a click using the.
Remove this link from the document. DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.
0コメント