BliarOut Posted September 12, 2007 Share Posted September 12, 2007 I'm building an app in PHP and I need to audit whenever anyone prints. IE 6 & 7 support the onbeforeprint() and onafterprint() function so I can trap whenever anyone prints even if it's not from a button that I've attached code to. The code below fires exactly when I want but I'd like to replace the alert with a MySQL insert that puts an entry in my log table. <script language="javascript" type="text/javascript"> function window.onbeforeprint() { alert('This fires before printing!'); } </script> Should the following work in theory (assuming all my variables are already declared etc)? <script language="javascript" type="text/javascript"> function window.onbeforeprint() { <!--Replace this alert('This fires before printing!'); --> <!--With This --> <?php mysql_query("INSERT INTO log (UserID, EventType, IPAddress) VALUES ('$_SESSION[FullName]', 'Permit no " ."$NewPermitID". " Printed', '$_SESSION[iP]')") or die(mysql_error()); ?> } </script> Quote Link to comment Share on other sites More sharing options...
liebs19 Posted September 12, 2007 Share Posted September 12, 2007 I don't think you can do php inside of javascript. There might be a solution using AJAX, but I only know a little Ajax so I can't help you there. The php code is processed by the server before the browser ever gets the document containing the HTML and javascript. Quote Link to comment Share on other sites More sharing options...
BliarOut Posted September 12, 2007 Author Share Posted September 12, 2007 I should have just tried it, it works! :-) If anyone wants to audit prints sent from a browser window into a MySQL database this will do the trick. Only works in IE as FF doesn't support the onbeforeprint() function. Quote Link to comment Share on other sites More sharing options...
liebs19 Posted September 12, 2007 Share Posted September 12, 2007 Interesting! I'll have to remember this one. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.