How can I Print then automatically close window ?

Page: 1

Author Post
tobtob
Guest
Is there an easy way to make the original floatbox window close after using the print function ? The new "print" window closes fine but I'd like to be able to close the original window too.
If anyone can help please make it simple.... I'm only a novice with JavaScript .
Thanks.
Administrator
Registered: Aug 2008
Posts: 3382
This is pretty easy to do, but you have to modify the floatbox.js code.

In the standard v3.24 floatbox.js file, at line 2384 (close to the bottom), find:
setTimeout(function() { win && win.print(); win && win.close(); }, 200);
return true;

Between those two lines, insert the following line:
this.end();
tobtob
Guest
I'd like to use the newest version 3.5.0 . I don't see anything like the "patch" you provided above. Can you describe a way to do this in the newest version ?
Thanks.
Administrator
Registered: Aug 2008
Posts: 3382
In the new version you can do this:
Near the bottom of modules/printContents.js, find the line:
pdoc.write('<!DOCTYPE html><html><head>' + styles + '</head><body>' + html +

and add an unload function like this:
pdoc.write('<!DOCTYPE html><html><head>' + styles + '</head><body onunload="window.opener.fb.end();">' + html +

In the next release I'll have an afterPrint callback function available which will do this much more cleanly (i.e., not by editing the code).
tobtob
Guest
Thanks, that worked perfectly. I like the idea of having a " afterPrint callback function " that can be set. Other than editing the code. Good job !

Page: 1