Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most popular in JavaScript. JavaScript console. As in the below html, when the 'Save' button is pressed, the input value should save in the user computer as a. You can use following uri to emulate an external text file.
Just copy the code to your address bar to see what would happen. Some old fashioned browsers don't support this feature. Full list. You can do that by creating a blob-url and a link to it. The link and not a button! 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. Asked 7 years, 5 months ago. Get certified by completing a course today! If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:.
Example Specify a value for the download attribute, which will be the new filename of the downloaded file "w3logo. Report Error.
It does make a file and downloads it, but the file is empty. No content. Any ideas why? Haven't tested on IE If your download is small, this works fine: document. If you just want to convert a string to be available for download you can try this using jQuery. Rick Rick Scape data with encodeURI might be needed as I suggested here before being able to comment: stackoverflow. Dzarek Dzarek 5 5 silver badges 9 9 bronze badges.
Ludovic's answer includes this big, plus support for the other browsers. Erik 1 1 gold badge 7 7 silver badges 21 21 bronze badges. Mostafa Mostafa 1, 16 16 silver badges 30 30 bronze badges. Text Encoder is highly experimental right now, I'd suggest avoiding or polyfilling it. What are the differences between this approach and creating a Blob?
Based on Rick answer which was really helpful. I was not able to accept the suggestion. I updated the code. Caniuse support table for Blob: Here is a Fiddle. This below function worked.
Denys Rusov Denys Rusov 5 5 silver badges 6 6 bronze badges. Sweta Jain 1, 1 1 gold badge 13 13 silver badges 28 28 bronze badges. Subhan Ali Subhan Ali 1 1 1 bronze badge. I had considered that, but from a user-friendliness point, this is disastrous. Also, the file has to be saved with a CSV extension.
Try telling that to your users. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast what if you could invest in your favorite developer?
Who owns this outage? Building intelligent escalation chains for modern SRE.
0コメント