3

I am trying to embed two URLs in the same clickable text; so after a person clicks on the text, he/she is directed to two webpages (I don't really care if this happens in two windows or two tabs). A command like:

\href{https://projecteuler.net/about;https://en.wikipedia.org/wiki/Project_Euler}{Project Euler}

Is this possible?

philomathic_life
  • 514
  • 3
  • 18

1 Answers1

1

That is an interesting quest. It is a good question with HTML alone, not to mention Latex.

Doing this with Javascript for the browser is standard fare. See this post for the simplest case by JS onclick method, or this post, or this post (for the same or other methods).

<p><a href="#" onclick="
        window.open('http://google.com');
        window.open('http://yahoo.com');
   ">Click to open Google and Yahoo</a></p>

Javascript is supported by the hyperref package, according to the long list of accepted methods in the hyperref docs. So it may be possible to do even exactly as shown, with onclick="..." in \href{} (untested). For a demonstration of far more involved JS see this post (with insdljs package). For a possible non-JS approach using 'nested actions' via hyperref's option nextactionraw see this post.

In short, it should be quite possible to use Javascript with hyperref and then you're golden.


There is also an old trick of how to do it with HTML, see first answer in a link above

<a href="#" class="yourlink">Click Here</a>

If this still works perhaps it is possible to slip it to hyperref, which may then just do it, without JS. (See an answer in one of the links above for how to define the css class if this is of interest.)

Community
  • 1
  • 1
zdim
  • 64,580
  • 5
  • 52
  • 81
  • Wow! Thank you very much for the very informative response. I will definitely take a thorough read of those links and try to implement the code. Thanks again! – philomathic_life Mar 23 '16 at 14:24
  • Well, in an attempt to avoid using JavaScript, I implemented the suggested `nextactionraw`; and it worked beautifully! I understand that not all PDF readers will be able to execute it properly, but that's a "risk" I'm willing to live with. – philomathic_life Mar 23 '16 at 16:13
  • @basketballfan22 Thank you for feedback! Good to know that that method works, too. Yes, it will depend on the reader. If you ever need to tweak it, JS should work. (I'll let you know if I get around to test it.) – zdim Mar 23 '16 at 18:03