Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added potential fix for iOS devices. #142

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions FileSaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,24 @@ var saveAs = saveAs
, fs_error = function() {
// don't create more object URLs than needed
if (blob_changed || !object_url) {
object_url = get_URL().createObjectURL(blob);
}
if (target_view) {
target_view.location.href = object_url;
} else {
var new_tab = view.open(object_url, "_blank");
if (new_tab == undefined && typeof safari !== "undefined") {
//Apple do not allow window.open, see http://bit.ly/1kZffRI
view.location.href = object_url
}
//I found this to help with saving on iOS devices. Of course it doesn't actually save
//because of apple restrictions, but the link opens. - Martavis P.
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
object_url = reader.result;
if (target_view) {
target_view.location.href = object_url;
} else {
var new_tab = view.open(object_url, "_blank");
if ((new_tab == undefined && typeof safari !== "undefined") || /(iPad|iPhone|iPod)/g.test(navigator.userAgent)) {
//Apple do not allow window.open, see http://bit.ly/1kZffRI
view.location.href = object_url;
}
}
}
}

filesaver.readyState = filesaver.DONE;
dispatch_all();
revoke(object_url);
Expand Down