Forum Moderators: open

Message Too Old, No Replies

Event After Print or Cancel?

         

Brett_Tabke

8:12 pm on Feb 5, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Printing the current page is as simple as:

<body bgcolor="#FFFFFF" onload="window.print()">

Is there a way to capture an event after they either press OK or cancel on the printer options dialog?

eg: after they print the page, I want to come back to the js to do something else with the page...

DrDoc

8:32 pm on Feb 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The best I could come up with was something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function printme() {
window.print();
document.body.onfocus = doneyet;
}
function doneyet() {
document.body.onfocus = "";
alert("after print dialog");
}
</script>
</head>
<body>
<a href="javascript: printme()">print me</a>
</body>
</html>

DrDoc

8:33 pm on Feb 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



... there is no way of catching a return value from the print dialog itself to know whether they actually printed or not.

Brett_Tabke

10:24 pm on Feb 5, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Imagine they click to print a page - such as a printer friendly version of a reciept. After they do that, I want to take them back to the order page.

An interesting approach you took there. That might just work in ie, but opera doesn't fire the focus afterwards (it does if you click away and then back...)

looks like that will suffice though... thanks!

DrDoc

10:46 pm on Feb 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function printme() {
window.print();
document.body.onmousemove = doneyet;
}
function doneyet() {
document.body.onmousemove = "";
alert("after print");
}
</script>
</head>
<body>
<a href="javascript: printme()">print me</a>
</body>
</html>

This works in Opera, but not in IE :)