0

I have a pdftron webviewer and I am trying to access it outside the config.js. This answer suggests to access iframe variables through contentWindow and get hold of readerControl.

But the problem is the iframe created by PDFTron WebViewer has a random id attribute. in order for us to confidently use it, we nee to set the id or class of the iframe to what we know of. I am trying to access the enclosing iframe using the document object which is inside it. I have found the solutions on how to access the other way around.

$(document).parents()

is null

My HTML

<head>
</head>
<body>
 <iframe id="random_number">
  #document
 </iframe>
</body>
Community
  • 1
  • 1
gmuraleekrishna
  • 3,375
  • 1
  • 27
  • 45

1 Answers1

1

The iframe can confidently be grabed by selecting within the viewer element. All you need is the id of the element you provided when instantiating WebViewer

<div id="viewer"></div>

$(function() {
    var viewerElement = document.getElementById("viewer");
    var myWebViewer = new PDFTron.WebViewer({
        path: "lib",
        type: "html5",
        initialDoc: "GettingStarted.xod"
    }, viewerElement);
});

var iframe = document.querySelector('#viewer iframe')

Kristian
  • 26
  • 1