Sapphire
Sapphire

Reputation: 1169

How to open hyperlinks in a new tab/window

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?

Upvotes: 3

Views: 4173

Answers (2)

Ravi Jayagopal
Ravi Jayagopal

Reputation: 940

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.

Upvotes: 1

Sapphire
Sapphire

Reputation: 1169

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

Upvotes: 3

Related Questions