Below is the javascript code that worked fine for me in IE 8 in Windows XP.
<script type="text/javascript"> function printFrame(frameId) { var iframe = $('#'+frameId)[0]; iframe.contentWindow.focus(); iframe.contentWindow.print(); } </script
The above function is called, then on the parent page the "Print Frame" button is clicked.
<iframe id="testFrame" src="" name="testFrame"> </iframe> <input type="button" onclick="printFrame('testFrame')" value="Print Frame"/>
I recently upgraded my machine to Windows 7 and IE 8 to IE 11.
Now the same function does not give the expected result of printing the contents of the iframe. I tested this in chrome v34, firefox 30. This seems to work in them except IE 11.
When researching, I found that when an iframe src is dynamically set, iframe.contentWindow does not return an excluded iframe window object.
I tried using window.print () inside jsp in an iframe. This seems to work if src does not change dynamically. But I need to change the iframe content for the dynamic job to match the selection in another drop-down list on the parent page.
For example, check the link below in IE 11.
http:
The first time the link prints the content on an iframe. Then press the button. This causes the parent window to be sent to the printer instead of the contents of the iframe.
Then I tried another method. I wrote the code below in the contents of the iframe jsp and tried to access it from the parent page. I was unable to access the method itself. "script code in iframe jsp"
<script type="text/javascript"> function printFrame() { window.print(); } </script
"script code in parent jsp"
Try 1:
<script type="text/javascript"> function printMyFrame(frameId) { var iframe = $('#'+frameId)[0]; $(iframe).contents().printFrame(); } </script
Try 2:
<script type="text/javascript"> function printMyFrame(frameId) { setTimeout(function() { window.frames[frameId].contentWindow.printFrame(); }, 200); } </script>
I searched and implemented almost all google search methods to access the iframe window instead of the parent window. But it was not possible to print the contents of the iframe using IE 11.
Please tell me how to print iframe content in IE 11.