browser – a href download attribute does not work in the latest version of safari 12.1 13607.1.40.1.5

I am setting up a new xml file download web application and want to provide a link to download the client side xml file with Javascript.

According to caniuse.com (https://caniuse.com/#search=download), Safari> 10.1 supports the download attribute. Unfortunately, this does not seem to work in safari compared to other browsers like Chrome, Firefox. Basically, after clicking on a href element, it goes to the next screen and the download does not take place.

I wrote the following a href script for this purpose.

                                    var link = document.createElement ("a");
link.download = file name;
link.target = "_blank";

// Build the URI
link.href = DOWNLOAD_URL;
document.body.appendChild (link);
link.click ();

// clean DOM
document.body.removeChild (link); 

For this to work for what I did, it was the timeout added to the click, as shown in the code below, that started working. Check it –

                                var link = document.createElement ("a");
link.download = file name;

link.target = "_blank";
// Build the URI
link.href = DOWNLOAD_URL;
document.body.appendChild (link);

setTimeout (function () {
link.click ();

// clean DOM
document.body.removeChild (link);
DOWNLOAD_COMPLETED = true;
document.getElementById (& # 39; nextButton & # 39;). onclick ();

}, 500);

What I want to understand is why safari behaves differently from other browsers. Looks like the internal implementation of the download attribute in Safari is asynchronous to some extent

Am I making a mistake in my download script? Can you help me? Thank you so much!