fix: download file on SamsungBrowser with block auto download (fixes #660)
SamsungBrowser has a settings enabled by default called "Block automatic downloads" that basically blocks all downloads that are not initiated by user interaction, thus making the call setTimeout(function () { click(a) }, 0) impossible to download a file on this browser, only if the user disables the settings option.
By checking the user agent for SamsungBrowser and calling click(a) instead of setTimeout(function () { click(a) }, 0) the function saveAs work as expected when called from an event initiated by the user. (button click)
Tested on SamsungBrowser 12.0.1.47 with a Smasung S6 SM-G920I.
Code used to test:
<html>
<head>
<script src="FileSaver.min.js"></script>
</head>
<body>
<button onclick="download()">download</button>
<script>
var testCsv = "this,is,a,row\nthis,is,another,row";
function download() {
var blob = new Blob([testCsv], { type: 'text/csv;charset=utf-8;' });
saveAs(blob, "test.csv")
}
</script>
</body>
</html>
Fixes #660
Pardon my question, but what is the purpose of the setTimeout with 0 milliseconds in the original code anyway?
Hello any update on this? will this be released yet? Also does this really fix it? I guess not I have tried something similar locally and same result it fails to download while block automatic downloads is on.
This needs to change to use window.open which works with Samsung Browser.. window.open(blob) though the file name will be lost but it will work.