I have a problem I can’t solve. The following function inputs a file path and name and downloads the file. It works for chrome and edge browsers but with Vivaldi and pale moon browsers it will work once but not a second time. You need to reload the browser for it to work again. I have isolated the problem to this function alone. The alert works for all browsers, (first and second times) and shows the appropriate file path and name but no download takes place after the first successful attempt. There is no error in console. I thought that perhaps the browser didn’t like the creation of ‘var a’ a second time so included the ‘a.remove()’ but it makes no difference.
function StartDownload(filePath, fileName) { // this is the function to download the book. Creates an html object 'a', adds the url to it, and then downloads it
//alert("got here: " + filePath + " fileName is: " + fileName);
var a = document.createElement("a");
a.href = fileUrl;
a.setAttribute("download", fileName);
a.click();
//a.remove();
}
Could anyone suggest possible reasons why this code won’t download in those browsers after the first time?