Javascript hyperlink pdf document to change parent window URI

I have an HTML (parent) webpage containing a hyperlink. When clicked, a new window opens and another HTML document (child) is displayed:

<a href="/testhtml.html" target="_blank">Open Child</a> 

Inside the child document are several links, which are structured as follows:

  <a href="#" onclick='opener.window.location.href="/somewhere.html"; window.close();'>Make Parent Go Somewhere</a> 

Thus, the effect is that you can click the link in the child window, this will cause the parent window to go to the new uri and then close. It works great.

I would like to do the same with PDF as a child document. I can embed hyperlinks in PDF just fine or even embed Javascript:

  13 0 obj << /Type /Action /S /JavaScript /JS (opener.window.location.href="/somewhere.html";) >> endobj 

Javascript runs beautifully, but the opener object is undefined. ( ReferenceError: opener is not defined 1: Link:Mouse Up ) Is what I want to do is even possible? What would be the object that I would use to access the uri opening window?

PS: If this is a problem, I have some control over the target user environment. I can indicate that they use Acrobat Reader and even a later version.

+4
source share
2 answers

HTML and PDF do not use the same object model. However, you can make HTML and PDF JS talk to each other:

Notification when a user clicks a link in an embedded PDF file

+2
source

One easy way to achieve your goal is to create a PDF hyperlink using href="javascript:myfunction()" and define myfunction() on your HTML web page. The resulting HTML file will look something like this:

 <html> <head> <script type="text/javascript"> function myfunction(){ alert("captcha!"); } </script> </head> <body> <object data="myfunction.pdf" type="application/pdf" width="100%" height="100%"> </object> </body> </html> 

And your hypertext PDF object will look like this:

 <</Type /Action /S /URI /URI (javascript:myfunction\(\))>> 

Inside myfunction (), you can use the HTML object model as usual.

0
source

All Articles