简体   繁体   中英

Safari 9 XMLHttpRequest Blob file download

Hello JavaScript gurus,

I need a file download functionality using XMLHttpRequest (with responseType="blob") that works in Safari 9+.

At the moment I'm using FileSaver.js like this:

 var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'blob'; xhr.onreadystatechange = function() { if (xhr.readyState == 4) { // using FileSaver.js to save blob saveAs(xhr.response, filename); // notify download finished, resolve promise defer.resolve(true); } }; xhr.send(); 

which works fine in all main browsers but not in current version (9.x) of Safari. I'll get a "Failed to load resource: Frame load interrupted". Usually a download is a zip file but I also tried to set "application/octet-stream".

I have one requirement: I need to know when then download has finished on client-side so using an iframe is no option (I guess).

I'm thankful for any hint how to download a file in Safari using XHR (no Flash).

Thanks, Chris

Simple answer: There is no solution!

See also: https://forums.developer.apple.com/message/119222

Thanks Safari ... my new almost IE6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM