I am using AJAX to send form data to a server php file that builds and sends an html email. A portion of this data I am echoing on the server php file. The html that is echoed builds a table that I would like the user to print (on paper). I'd like to open the default browser print dialog so the user can print the table that he/she cannot see. I don't care if a new tab has to open displaying the echoed content. Is this even possible?
return that html form ajax request and then use javascript to print
This code is not tested
JQuery/Javascript
$.post("EmailFile.php", { "EmailParam": "EmailVal" },
function(data){
var HTML = data.EmailHTML;
var WindowObject = window.open("", "PrintWindow", "width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes");
WindowObject.document.writeln(HTML);
WindowObject.document.close();
WindowObject.focus();
WindowObject.print();
WindowObject.close();
}, "json");
PHP File (EmailFile.php)
$EmailData = $_POST['EmailParam'];
//...Send Email...
//..Build HTML...
$TableHTML = "<table></table>";
//Return HTML
$JSONArr['EmailHTML'] = $TableHTML;
echo json_encode($JSONArr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With