When I want to download a file from the server to local computer - in case of EDIT form I am placing the following code inside the Button "onclick" and works fine

Code: Select all
var f=$('#rap_location').val(); //get filename from the form
var link=sd_path+f; //sd_path defined as global variable
function download(dataurl, filename) {
var a = document.createElement("a"); a.href = dataurl;
a.setAttribute("download", filename);
a.click();}
download(link, f);

The following code is placed in the JS custome code:
Code: Select all
function download(dataurl, filename) {
var a = document.createElement("a"); a.href = dataurl;
a.setAttribute("download", filename);
a.click();}
function nuSelectBrowse(e){
.... collecting link and file name 'f' is ok
download(link, f);
}
"a" is generated properly when checking with console.log - but I do not know how to force "a" to be executed when I call the "download" function.
Do you have some suggestions how to modify the code to make it run properly from the Browse form?
When I use window.open (link,"myWindow"); it works fine in every place - but generally it opens files in the browser but I want to force them to be always downloaded.