iOS Chrome: Fix broken download button

The download button in pdf.js doesn't work in iOS Chrome.

  - It appears to be an issue with URLs from URL.createObjectURL.
    The URL is correct, but iOS Chrome won't even load the URL
    when `a.click()` is called in `download_manager.js`. Even
    if you manually visit the URL, you get a blank page.

  - Fix this by detecting iOS Chrome and disabling createObjectURL.

The `download_manager.js` `download` method wasn't checking
`PDFJS.disableCreateObjectURL`, so check it there, too.

  - Move the navigator.msSaveBlob check earlier, so that
    this doesn't change IE10 / IE11 behavior.

  - Remove the !URL check since pdf.js has a URL polyfill
    now.
This commit is contained in:
Daniel Johnson 2017-02-17 17:15:40 -08:00
parent cfaa621a05
commit 4fc64ceb76
2 changed files with 11 additions and 9 deletions

View file

@ -86,12 +86,6 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC || CHROME')) {
},
download: function DownloadManager_download(blob, url, filename) {
if (!URL) {
// URL.createObjectURL is not supported
this.downloadUrl(url, filename);
return;
}
if (navigator.msSaveBlob) {
// IE10 / IE11
if (!navigator.msSaveBlob(blob, filename)) {
@ -100,6 +94,12 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC || CHROME')) {
return;
}
if (pdfjsLib.PDFJS.disableCreateObjectURL) {
// URL.createObjectURL is not supported
this.downloadUrl(url, filename);
return;
}
var blobUrl = URL.createObjectURL(blob);
download(blobUrl, filename);
}