Javascript Print iframe contents only
I would not expect that to work
try instead
window.frames["printf"].focus();
window.frames["printf"].print();
and use
<iframe id="printf" name="printf"></iframe>
Alternatively try good old
var newWin = window.frames["printf"];
newWin.document.write('<body onload="window.print()">dddd</body>');
newWin.document.close();
if jQuery cannot hack it
Live Demo
Print iFrame content using Javascript
.contentWindow.print();
worked for me.
I've opened the PDF in iframe of fancybox and then called .contentWindow.print();
.
Though it's not supported in some older browsers.
trying to print iframe content but print the whole page instead
You may first check if the user agent is IE:
function printIFrameContent()
{
var ua = window.navigator.userAgent;
var msie = ua.indexOf ("MSIE ");
var iframe = document.getElementById("testFrame");
if (msie > 0) {
iframe.contentWindow.document.execCommand('print', false, null);
} else {
iframe.contentWindow.print();
}
}
Referred a similar answer on SO: https://stackoverflow.com/a/19639241/1500851
Related Topics
Check If an Array Is Empty or Exists
How to Conditionally Import an Es6 Module
Activexobject in Firefox or Chrome (Not Ie!)
How to Insert Text into the Textarea at the Current Cursor Position
How to Fix Jslint Error 'Don't Make Functions Within a Loop.'
How to Create Separate Angularjs Controller Files
Are Es6 Classes Just Syntactic Sugar for the Prototypal Pattern in JavaScript
What Is the Instanceof Operator in JavaScript
How to Link Each User to Their Data in Firebase
Casting Plain Objects to Class Instances in JavaScript
How to Convert the "Arguments" Object to an Array in JavaScript
How to Get the Day of Week and the Month of the Year
What Is Returned from a Constructor
Why Should I Use a Semicolon After Every Function in JavaScript