开发者

Catch a pdf hyperlink click from an iframe

开发者 https://www.devze.com 2022-12-18 06:02 出处:网络
I\'m loading pdf\'s into an iframe on my web page by setting the src of the iframe to the path of the pdf document.

I'm loading pdf's into an iframe on my web page by setting the src of the iframe to the path of the pdf document. Th开发者_如何学Gois works as I'd like for viewing the pdf.

The problem is that some of the pdf's have hyperlinks in them to external websites which, when clicked, load the external website in my iframe.

So my question is: is it possible to catch the pdf's hyperlink click in javascript in the parent browser window, set the target to either top or blank and then redirect the request?

Unfortunately the pdf's are supplied by a third party so I don't have access to change the documents themselves.


Some ideas:

  • You can try hooking into the iframe's load/readystatechange event to catch when the iframe is loading another url.
  • You can "poll" the iframe every n interval and compare the src attribute to the URL of the pdf.

After you catch the change, you can redirect and open a window with the proper url. But browsers may block the JS pop-up window.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号