Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chrome blocks ajax requests when print preview is opened on child window

There are 2 files: index.html and print.html

First one contains a button that opens print.html using simple command:

window.open("print.html", "_blank", "menubar=yes,toolbar=yes,status,scrollbars,resizable");

print.html contains only one button that opens print preview dialog:

<button onclick="window.print();">

The problem appears when print preview dialog is opened. In this case any action on index.html - i.e. the other file that initiate ajax request - is temporary blocked and put into queue. And only when preview is closed browser fires all requests.

I can see it only in Google Chrome (24.0.1312.52 m).

Can anybody confirm that this is Chrome's bug?

like image 982
John Smith Avatar asked Jan 22 '13 15:01

John Smith


People also ask

How do I fix print preview in Google Chrome?

If your Chromebook can't load the print preview, restart your laptop, printer, and router. Additionally, remove and set up the printer again. If the issue persists, clear your Chrome cache, and disable your extensions. You can also reset your browser to default settings.

Can AJAX be blocked?

ajax has async property. If you set it to false it will block.

Does AJAX work in Chrome?

New! Save questions or answers and organize your favorite content. Learn more.


1 Answers

there is a Chrome bug where window.print() does not work when there is a tag in the DOM. It might be solved by calling this function:

function printPage() {
    window.print();

    //workaround for Chrome bug - https://code.google.com/p/chromium/issues/detail?id=141633
    if (window.stop) {
        location.reload(); //triggering unload (e.g. reloading the page) makes the print dialog appear
        window.stop(); //immediately stop reloading
    }
    return false;
}
like image 72
Syed Amir Bukhari Avatar answered Sep 19 '22 05:09

Syed Amir Bukhari