Chrome window.print() window.close() results in 'print preview failed'. Solution?

javascript window print close
body onload=window print window close
window print close event
window.print cancel event
after print window close
await window print
window.print not working in chrome
window print not working

I have a print page that opens in a new tab or window. The resulting page opens a print dialog. After the user makes a selection on the print dialog, the page then closes the tab/window.


This used to work great in the major browsers, but one of the latest versions of Chrome breaks this (i.e. 14.0.835.202).

I receive the following message from what I guess is the chrome print plugin: "Print preview failed".

Does anyone have a solution to close the Chrome tab/window after printing?

I don't think there are any standardised print events. IE has a couple, but I realise that doesn't help you for Chrome.

I think you might be left with only two options. A manual close button or some form of delay using setTimeout.

Close window automatically after printing dialog closes, Using Chrome I tried for a while to get the window.onfocus=function() { window. close(); } and the <body onfocus="window.close()"> to work. My results:. If you call window.close() immediately then the dialogue is not seen by the user. The user needs to click "Print" within the dialogue. This is not the same as on other browsers where the print dialogue is part of the OS, and blocks the window.close() until dismissed - on Chrome, it's part of Chrome, not the OS.

I just managed to come up with a solution that fits me. I started out with the reply from Peru but didn't want to use jQuery in this solution.

window.onload = function () {
  setTimeout(function(){window.close();}, 1);

For some reason Chrome dont start the timeout timer until the print dialog is closed.

chrome window.print() window.close() – Life in USA, chrome window.print() window.close(). Posted by LeOn on October 30, 2013. Chrome used to open a seperate window containing just the element i wanted� This is a cross-browser solution already tested on Chrome, Firefox, Opera by 2016/05.. Take in mind that Microsoft Edge has a bug that won’t close the window if print was cancelled.

This question is a top hit on Google so I thought I would add what I found, even though it does not exactly mirror your situation. If you have a link that calls window.print() then its onclick handler must return false or you get the error. This is true even if the link is a hash and goes nowhere!

Print is unavailable because the page you were trying to print has been closed

To fix this make sure you add return false to the link.

<a href="#" onclick="window.print(); return false;" >Print</a>

Here is the Chromium bug that addresses this. It is marked as fixed for Chrome 17 (not yet released) and I have verified the fix in Chrome 18.

359627, We open a popup window and in that popup call print() version you are using has a bug that means closing this window will result in chrome being unstable. I have a tab open when the user clicks a button. On the onload I have it bring up the print dialog, but the user asked me whether it was possible that after it sends to the printer to print, if the tab could close itself.

Similar issue, I had.

FYI FOR ALL AS OF VER 17+ I was using the jquery plugin, printElement and had found a way to edit it so I could close the window, even in chrome ... then they updated to this new print thing! I have a solution yet again.


Chrome used to open a seperate window containing just the element i wanted 
printed and its relative css.  That window then spawned the .print command 
which opened another window containing print preview. By adding a simple 50 
millisecond timeout i was able to close the previous window without hurting 
the print preview.

The NEW Problem

Chrome no longer opens a new window for their print preview. Instead it 
opens a "dialog with overlay" in the current page to be printed (aka, our 
new blank page containing just the element for print). Thus, when my timer 
kicked in, it wouldn't close the page immediately, but as soon as the dialog 
code closed.  The problem was, it closed so fast, the print command never 
made it to its service and thus nothing was printed to pdf 
(what our clinic uses).

The NEW Solution

I knew increasing the timer was no help, since it would just close at the end and could still stop the dialog from printing. Instead, I add a script link to the latest jquery build to the header of the new about page and then added a hover to the body of the page to be printed. On hover ... CLOSE!!! And guess what ... It works PERFECT!!!

In summery, if you're using a blank page to print in chrome and need to close the page after your element/whatever is printed, simply add a hover event on the body of that page (Or on inner html) that closes the window. Then, when you have selected a print method and hit print, it will print and close the dialog, leaving you that annoying window. Simply move your mouse a scooch and VIOLA! the annoying pop up window is GONE!

Javascript window.print() in chrome, closing new window or tab , $(w.document).ready(function () { w.focus(); w.print(); w.close(); });. The issue I'm seeing is that in Chrome, if I close the tab or window that is opened for the print� When one uses the print button, the page (node/n) is replaced by the printer-friendly version (print/n); one must use the Back button to redisplay the original page. This doesn't happen with the PDF function. We've tried using the option to open the print function in a new window, but that doesn't happen (the link doesn't contain a target directive). This has been tested with Chrome, Firefox

All solution above doesn't solved my problem, using this code solved my problem

setTimeout(function () {
    }, 1000); 

Javascript, If URL is not set then method open a blank window. name: It is an This method is used to close the window which are opened by method. Syntax: Google Chrome; Internet Explorer; Firefox; Opera; Safari Method � Javascript | Window confirm() Method � JavaScript | Window print() Method� window.close() Before going to discuss further, I think you should aware of the fact that window.close() method will able to close only the tab that is open by using the method. So, to close the current tab in javaScript, it must have to be opened by using the method.

Window open + print + close, has some issues in non-Firefox , 4 reproduces 3, but Chrome is too fast in executing the window.close() before the window.print() is ready. Finally, this is totally unrelated to the� Definition and Usage. The close() method closes the current window. Tip: This method is often used together with the open() method.

window.print() crashes if a 'print' event listener causes a rerender , The trigger seems to be a call to print() that results in a React state change useState's setState hangs when called in closed window #16585 sophiebits changed the title Calling window.print() can cause React to crash causes a rerender (Chrome, DEV-mode only) window.print() crashes if a 'print'� Definition and Usage. The print() method prints the contents of the current window. The print() method opens the Print Dialog Box, which lets the user to select preferred printing options.

close tab window when clicked on cancel print, i want to close the tab window when clicking on cancel print. Chrome and Edge's print page have their own canel button, when you click cancel, the tab will close. So I'd like to ask Could you also post the running screenshot of your result? onload="window.print()" onmouseover="window.close()">');� Printing a page involves creating/displaying a modal dialog which is not desirable during navigations and can cause several issues. Currently, Firefox already ignores print() during the unload handlers, and Chrome is broken in several ca

  • I would also attempt to use the handler you got from
  • I previously had in place: window.print(); setTimeout('window.close()', 1000); This used to work with Chrome, but it stopped working in the latest release. Chrome reports: "Print is unavailable because the page you were trying to print has been closed." If anyone disputes that a close button is the only option, please let me know! Thanks!
  • This worked for me on IE, Chrome & Firefox. I didn't test on any other browsers.
  • But when I am pressing ctrl+P before print preview dialog box. Tab is getting closed. Is there any workaround
  • This is the only solution that I have found that actually works. Kudos to you sir.