print part of page and close window on focus(cross browser)

function jst_print_service(sitrurl){
    var data = jQuery("#print_service_area").html();
    var mywindow = window.open('', 'my div', 'height=400,width=600');
    mywindow.document.write('<html><head><title>Service</title>');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);
    mywindow.document.write('</body></html>');
	mywindow.document.close();
    mywindow.print();
	//mywindow.onfocus = function() { mywindow.close(); }
setTimeout(function(){mywindow.close();}, 1);

    return true;
}

 

<a class="print_butn_area" id="jst_printService" href="javascript:void(0);" onclick="jst_print_service();">Print</a>

 

Leave a Reply

Your email address will not be published. Required fields are marked *