Skip to content

Commit

Permalink
Merge pull request #12286 from Snuffleupagus/bug-1661259
Browse files Browse the repository at this point in the history
Use a link, rather than `window.open`, when opening PDF attachments in Firefox (bug 1661259)
  • Loading branch information
timvandermeij authored Aug 26, 2020
2 parents 3e437ce + 1e5d4b6 commit a6f6689
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion web/pdf_attachment_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,22 @@ class PDFAttachmentViewer extends BaseTreeViewer {
encodeURIComponent(blobUrl + "#" + filename);
}
try {
window.open(viewerUrl);
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
window.open(viewerUrl);
} else {
// Since we have a full URL in the MOZCENTRAL-build, use a link rather
// than `window.open` since e.g. ad blockers may otherwise force-close
// the newly opened window and thus break viewing of PDF attachments
// (fixes bug 1661259).
const a = document.createElement("a");
a.hidden = true;
a.href = viewerUrl;
a.target = "_blank";
// <a> must be in the document, otherwise `a.click()` is ignored.
(document.body || document.documentElement).appendChild(a);
a.click();
a.remove();
}
} catch (ex) {
console.error(`_bindPdfLink: ${ex}`);
// Release the `blobUrl`, since opening it failed...
Expand Down

0 comments on commit a6f6689

Please sign in to comment.