PDF文档超链接javascript改变父窗口URI
我有一个包含超链接的 HTML 网页(父网页)。单击时,它会打开一个新窗口并显示另一个 HTML 文档(子文档):
<a href="/testhtml.html" target="_blank">Open Child</a>
子文档内部有几个链接,其构造如下:
<a href="#" onclick='opener.window.location.href="/somewhere.html";
window.close();'>Make Parent Go Somewhere</a>
所以效果是,您可以单击子窗口中的链接,它会导致父窗口转到新的 uri,然后自行关闭。这效果非常好。
我想对 PDF 作为子文档执行同样的操作。我可以在 PDF 中嵌入超链接,甚至嵌入 Javascript:
13 0 obj
<<
/Type /Action
/S /JavaScript /JS
(opener.window.location.href="/somewhere.html";)
>>
endobj
Javascript 可以很好地触发,但对象“opener”未定义。 (ReferenceError: opener is not Defined 1: Link:Mouse Up
) 我想要做的事情可能吗?我将使用什么对象来访问打开窗口的 uri?
PS:如果这是一个问题,我确实可以控制用户的目标环境。我可以指定他们使用 Acrobat Reader,甚至是它的更高版本。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTML 和 PDF 不使用相同的对象模型。尽管如此,让 HTML 和 PDF JS 相互对话是可能的:
当用户单击嵌入 PDF 中的链接时收到通知
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
实现目标的一种简单方法是使用
href="javascript:myfunction()"
创建 PDF 超链接,并在 HTML 网页中定义myfunction()
。生成的 HTML 文件将类似于:您的超链接 PDF 对象将是:
在 myfunction() 内,您将能够像往常一样使用 HTML 对象模型。
One easy way of achieving your goal is to create a PDF hyperlink with
href="javascript:myfunction()"
, and definingmyfunction()
in your HTML web page. The resulting HTML file would be something like:And your hyperlink PDF object would be:
Inside myfunction() you will be able to use the HTML object model as usual.