Try this,
var mywindow = window.open('', 'iFrameTagId', 'height=500,width=500');
mywindow.document.write('<html><head><title>title</title>');
mywindow.document.write('</head><body >');
mywindow.document.write(data);//iFrame data
mywindow.document.write('</body></html>');
mywindow.print();
mywindow.close();
Or you directly open this page and use below code while page load
$(document).ready(function () {
window.print();
setTimeout('window.close();', 100);
});
Updated Code
function iprint(ptarget) {
var mywindow = window.open('', 'ptarget', 'height=500,width=500');
mywindow.document.write('<html><head><title>title</title>');
mywindow.document.write('</head><body >');
mywindow.document.write($(ptarget).html()); //iFrame data
mywindow.document.write('</body></html>');
mywindow.print();
mywindow.close();
}
<iframe name="theiframe" id="theiframe" width="700" height="500" src = "http://localhost:54649/WebSite6/Default.aspx"></iframe>
<input type="button" class="btninput" value="print iframe" onclick="iprint('#theiframe');" />