From d271811740d4ac51186b207ca0017ae7f5de9260 Mon Sep 17 00:00:00 2001 From: Mike Lyons Date: Thu, 26 Feb 2015 13:26:41 -0500 Subject: [PATCH] Add option to open external links in new window --- src/display/annotation_helper.js | 3 +++ src/display/api.js | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/display/annotation_helper.js b/src/display/annotation_helper.js index 323617657a713..a64ee35f78291 100644 --- a/src/display/annotation_helper.js +++ b/src/display/annotation_helper.js @@ -217,6 +217,9 @@ var AnnotationUtils = (function AnnotationUtilsClosure() { var link = document.createElement('a'); link.href = link.title = item.url || ''; + if (item.url && PDFJS.openExternalLinksInNewWindow) { + link.target = '_blank'; + } container.appendChild(link); diff --git a/src/display/api.js b/src/display/api.js index 547fe6d8a1a9d..7cd8c57736e0a 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -160,6 +160,15 @@ PDFJS.verbosity = (PDFJS.verbosity === undefined ? PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ? 16777216 : PDFJS.maxCanvasPixels); +/** + * Opens external links in a new window if enabled. The default behavior opens + * external links in the PDF.js window. + * @var {boolean} + */ +PDFJS.openExternalLinksInNewWindow = ( + PDFJS.openExternalLinksInNewWindow === undefined ? + false : PDFJS.openExternalLinksInNewWindow); + /** * Document initialization / loading parameters object. *