Javascript framework navigation in ie11 with pdf

I have a simple webpage where 1 frame displays pdf and the other one is a menu bar.

<iframe src="bar.html" name="menu" ></iframe> <iframe src="doc.pdf" name="itempane" ></iframe> 

Using chrome, I can go from the menu bar to the parent and go back to the frame containing the pdf to print it

 var pWindow = window.parent; pWindow['itempane'].print(); 

Trying to do the same in IE11 gives an Invalid call object error.

you can see it at http://www.abhrdev.co.uk/main.html

What am I doing wrong / what makes IE different?

Greetings

Updated .....

I think I proved that this is not a javascript coding problem, but related to PDF processing in IE. On the next page

 <a href="javascript:printFromMain('pdfpane');">Print PDF</a><br/> <a href="javascript:printFromMain('htmlpane');">Print HTML</a> <iframe src="bar_1.html" name="menu" ></iframe> <iframe src="doc.pdf" name="pdfpane" ></iframe> <iframe src="doc.html" name="htmlpane" ></iframe> 

and this function

 function printFromMain(paneName) { var pWindow = window[paneName]; pWindow.focus(); pWindow.print(); } 

html page printing works, but not in pdf pWindow.focus () gives an invalid call object - any understanding of why this could be greatly appreciated

+5
source share
3 answers

After a few attempts, I finally get to work in IE11:

1) use an object tag instead of an iframe

2) run focus () / print () directly on the element

3) starts after a timeout to make sure everything is loaded. There may be a better way to do this (for example, use some kind of event listener), since the wait time should be long enough for it to work properly

 setTimeout(function () { var contentThingy = document.getElementById('itempane'); contentThingy.focus(); contentThingy.print(); }, 4000); 

An object (with the specified id) instead of an iframe:

 <object id="itempane" ... ></object> 

Note: does not work in chrome. One of the other options for other answers (i.e. Using ContentWindow) may be.

+1
source

Try using window.frames to get a frameList and refer to it by the name of the frame this way.

 var pWindow = window.parent; //reference the parent from the iframe var ifr = pWindow.frames.itempane; //get the pdf frame from the frame list ifr.focus(); ifr.print(); 
0
source

try it

 <iframe src="bar.html" name="menu" ></iframe> <iframe src="doc.pdf" ID="itempane" ></iframe> var otherPane = parent.document.getElementById("itempane"); otherPane.focus(); // OR otherPane.print(); // OR var doc = otherPane.contentWindow || otherPane.contentDocument; doc.focus(); doc.print(); 
0
source

Source: https://habr.com/ru/post/1202682/


All Articles