-->

Force PDF links within iframe to open in parent wi

2019-08-07 01:15发布

问题:

I'm trying to implement this in Confluence pages.

Basically, I have a PDF file (exported from Powerpoint), which has hyperlinks embedded, so when you click on the links in the PDF it opens whatever page the link is.

This PDF file is opened within an iframe in the Confluence page (which is created using a custom user macro).

Unfortunately, on Firefox and IE, the PDF links open the new page within the iframe, rather than the parent window. Chrome's inbuilt PDF viewer works fine (opening in the parent window).

Also unfortunate is that I don't know much about javascript or HTML. The code we are using currently for the 'create iframe' custom macro in Confluence is as follows:

## @param Url:title=URL|type=string|required=true|desc=URL for the iFrame 
<script type="text/javascript"> 
jQuery(function($) { 
    var ratio = Math.sqrt(2); 
    var target = $("#f"); 

    function fixRatio() { 
          target.width("100%"); 
          if (target.width() > 1000) { 
                  target.width(1000); 
          } 
        target.height(Math.ceil(target.width() / ratio)); 
    } 

    $(window).bind("resize", fixRatio); 

    fixRatio(); 
}); 
</script> 

<iframe id="f" src="$paramUrl" width="100%" style="border:0">x</iframe> 

Now, most of this is just to do with sizing the iframe approximately to the PDF file (for aesthetic reasons).

Basically what I want to know is how do I get any links from the PDF opening not in the iframe but in the parent window?

I thought about performing an operation on the iframe window unload, something like

window.onunload=function()

within the javascript, or

<body onunload="somecode">

in the HTML, but I'm not sure where to place it or what the code is that I would need to force the new page to be passed to the parent window and rendered there instead of the iframe.

I've tried

<base target="_parent" />

but because the PDF viewer is separate from the rest of the page in the iframe it doesn't seem to work.

Sorry I'm very new to this, we did get a someone to help us but he wrote the code then didn't stick around to help with any issues, and I've only seen my first HTML and javascript today! So trying to learn fast...

Thanks!