Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to open external links in new window #5758

Merged
merged 1 commit into from
Feb 27, 2015

Conversation

mjlyons
Copy link

@mjlyons mjlyons commented Feb 24, 2015

This change adds a PDFJS.openExternalLinkInNewWindow boolean, which opens links in a new window when enabled. The default now and previous to this change, clicking on an external link will open the link the same window (and navigate away from PDF.js).

@@ -217,6 +217,9 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {

var link = document.createElement('a');
link.href = link.title = item.url || '';
if (PDFJS.openExternalLinksInNewWindow) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this set target = '_blank' for both external and internal links, when the condition is true? You probably need to do something along these lines instead:

if (item.url && PDFJS.openExternalLinksInNewWindow) {

@mjlyons mjlyons force-pushed the ext-link-new-window branch from 029bb5f to d271811 Compare February 26, 2015 18:36
@mjlyons
Copy link
Author

mjlyons commented Feb 26, 2015

@Snuffleupagus - I didn't realize internal links would hit this codepath but make sense and added the url check. FWIW, when I created a link to another page (in Acrobat XI) it correctly jumped to the page even without this check, put perhaps this wasn't an "internal link"?

@Snuffleupagus
Copy link
Collaborator

If you look at annotations_layer_builder.js#L103, you will see that all links are fetched in the same way by the viewer code. Further down, at annotations_layer_builder.js#L126, you'll see the difference between the way internal/external links are handled.

With the current way that internal destinations are implemented, your first patch "worked" correctly more or less by accident :-)
But in order for this patch to work as advertised (i.e. only for external links) and to avoid any future issues (e.g. if we ever re-factor the link code for the viewer), we need to make sure that it only applies to external links. I hope this helps explain things, if not just ask!

@mjlyons
Copy link
Author

mjlyons commented Feb 26, 2015

Cool, totally make sense! Is there anything else for me to do? Not trying to be pushy, rather, I haven't contributed to pdf.js before and want to make sure you're not waiting on me =)

@Snuffleupagus
Copy link
Collaborator

Is there anything else for me to do? Not trying to be pushy, rather, I haven't contributed to pdf.js before and want to make sure you're not waiting on me =)

This seems fine to me; but given that adding a configuration option usually means that you'll have to support it forever, I figured it would be a good idea for one of the devs to sign off on this.

/cc @yurydelendik, @brendandahl Any feedback on this PR?

@yurydelendik
Copy link
Contributor

but given that adding a configuration option... have to support it forever

yeah, eventually we have to move those properties for stateless objects. we can keep that where it is, but in the future add migration path to default those objects properties to set values from obsolete properties in the PDFJS.

Just a reminder for users of such properties to set them once before getDocument is invoked, to avoid confusion in the future.

Thanks for the patch.

yurydelendik added a commit that referenced this pull request Feb 27, 2015
Add option to open external links in new window
@yurydelendik yurydelendik merged commit 4c2640d into mozilla:master Feb 27, 2015
@mjlyons mjlyons deleted the ext-link-new-window branch March 2, 2015 17:09
speedplane pushed a commit to speedplane/pdf.js that referenced this pull request Mar 4, 2015
Add option to open external links in new window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants