Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
43
rated 0 times [  44] [ 1]  / answers: 1 / hits: 21907  / 11 Years ago, wed, october 30, 2013, 12:00:00

I currently have this code:



function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
pom.click();
}

download('test.html', string);


The string contains a lot of html code that gets written in an .html file.

The above code is working perfectly:
On a button click, the browser (chrome) automatically downloads an html file with the string content written in it.



Now, what I want to do is, instead of chrome downloading the file automatically, it should open a save-as dialog box and ask the user the location and name of the file, and then download it to that location.



A quick simple reply would be really appreciated.


More From » html

 Answers
14

My browser was set to automatically download all files in default location which is why not only this file but all other files from my browser were downloaded directly without the save prompt dialogue. Changing the settings in browser to 'always ask the download location' worked.


[#74617] Tuesday, October 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarrettw

Total Points: 300
Total Questions: 98
Total Answers: 103

Location: Saudi Arabia
Member since Mon, Sep 5, 2022
2 Years ago
;