Close browser window after print

On inheriting a site with a print popup window – ie a print button that is supposed to open another invisible window for print formatting, print said page, then invisibly close. I encountered a bug that occurred on newer browsers in the popup javascript from this code:


This is expected to show the print dialog and then close the window with print formatting, but it doesn’t! Most just ignore the close() call altogether and I think IE throws some kind of error, I had a different issue in IE that I fixed afterwards so I’m not sure what happens in IE. After some searching the best solution (sans jQuery) I found is linked at the top. Making use of timers and detecting when the page has finished loading as the print() call prevents the js from processing any further so it stops the page from being counted as “ready”.

Posted on June 17, 2013, in Javascript and tagged , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: