2

The default behaviour of PDF.js is to open hyperlinks in the existing window. However, this may not be the desired outcome at all times. How can we open hyperlinks in a new window/tab and override the default behaviour?

2 Answers 2

3

There's a property called PDFJS.externalLinkTarget. This is set to NONE by default. Set this to BLANK and target='_blank' attributes are added to all anchors. That will open your hyperlinks in a new tab/window.

Possible values:

  • NONE [default]
  • SELF
  • BLANK
  • PARENT
  • TOP

Docs

0
0

In build/pdf.js, replace the line below:

target: data.newWindow ? _display_utils.LinkTarget.BLANK : linkService.externalLinkTarget,

With this one:

target: _display_utils.LinkTarget.BLANK,

And then all links will always open in a new tab. I suppose you could pass it as a parameter. I never looked into how, because I wanted it to be permanent anyway, so hard-coded it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.