I'm setting up a new download xml file web application and want to provide link to download xml file client-side with Javascript.
I have written the following a href script for this purpose.
var link = document.createElement("a");
link.download = filename;
link.target = "_blank";
// Construct the URI
link.href = DOWNLOAD_URL;
document.body.appendChild(link);
link.click();
// Cleanup the DOM
document.body.removeChild(link);
To make it working, what i did is added timeout on click event as show in below code and it started working. Please check -
var link = document.createElement("a");
link.download = filename;
link.target = "_blank";
// Construct the URI
link.href = DOWNLOAD_URL;
document.body.appendChild(link);
setTimeout(function() {
link.click();
// Cleanup the DOM
document.body.removeChild(link);
DOWNLOAD_COMPLETED = true;
document.getElementById('nextButton').onclick();
}, 500);
What i want to understand why safari behaves differntly as compare to other browser. Looks like safari internal implementation of download attribute is async to some extentDo I make an error in my download script? Can you help me? Thanks a lot!