Reputation: 13209
I have an HTML web page (the parent) that contains a hyperlink. When clicked, it opens a new window and displays another HTML document (the child):
<a href="/testhtml.html" target="_blank">Open Child</a>
Inside the child document are several links that are constructed like this:
<a href="#" onclick='opener.window.location.href="/somewhere.html";
window.close();'>Make Parent Go Somewhere</a>
So the effect is that you can click on a link in the child window, it will cause the parent window to go to that new uri, and then close itself. This works wonderfully.
I'd like to do that same thing with a PDF as the child document. I can embed hyperlinks in the PDF just fine, or even embed Javascript:
13 0 obj
<<
/Type /Action
/S /JavaScript /JS
(opener.window.location.href="/somewhere.html";)
>>
endobj
The Javascript gets triggered nicely, but the object "opener" is not defined. (ReferenceError: opener is not defined 1: Link:Mouse Up
) Is what I'm looking to do even possible? What would be the object I would use to access the opening window's uri?
PS: If it's a problem, I do have some control over the user's target environment. I can specify that they use Acrobat Reader, and even a later version of it.
Upvotes: 4
Views: 4192
Reputation: 10418
One easy way of achieving your goal is to create a PDF hyperlink with href="javascript:myfunction()"
, and defining myfunction()
in your HTML web page. The resulting HTML file would be something like:
<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 hyperlink PDF object would be:
<</Type /Action /S /URI /URI (javascript:myfunction\(\))>>
Inside myfunction() you will be able to use the HTML object model as usual.
Upvotes: 0
Reputation: 15870
HTML and PDF don't use the same object model. None the less, it's possible to get HTML and PDF JS to talk to one another:
Getting notified when the user clicks a link in an embedded PDF
Upvotes: 2