3

Problem:

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

Details:

I have a web page - ParentPage.html with a link to child page - PrintPage.html

a href="PrintPage.html"  target="_blank"   

Then on my PrintPage.html I have JavaScript that invoke window.print()

$(document).ready(function() {

        window.print();
}

If user goes to ParentPage.html without closing that print modal on PrintPage.html and click some button that fires Ajax calls, they are blocked until the print modal is closed.

This should be a known problem with Google Chrome, other browsers(IE, Firefox) have similar issue but they don't become problem because they simply don't allow user to navigate to other tab other than the current opened print page.

I found related questions here on SO but no solution:

Chrome browser unable to make a server call when print preview is opened

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

It would be best to make the parent window's Ajax not blocked. I feel it might be possible because not all tab's Ajax calls are blocked, only this parent window. So if there's a way to make the child page - PrintPage.html not a child page of ParentPage.html, that would work.

A less ideal way would be to close the print modal on PrintPage.html when I detect user clicking on ParentPage.html. Then reopen the print modal when PrintPage.html is focused. The reopen modal part is easy, but I don't know how to close print modal from a different tab.

If above two ways won't work, I think I'll have to display a warning when the print modal is opened and user is trying to click ajax call button at ParentPage.html. Detecting if the print modal is opened from ParentPage.html might not be easy either.

Any help would be appreciated!

Community
  • 1
  • 1
David Shen
  • 31
  • 2
  • Have a look at this, gotta make sure you close first before the ajax call http://stackoverflow.com/questions/15125577/closing-child-window-from-parent-window – Rob Schmuecker Jun 24 '15 at 17:46
  • Thanks @RobSchmuecker, but that would require me to use window.open() which is pop up window and may be blocked by the browser. – David Shen Jun 24 '15 at 18:01
  • If the content of `PrintPage.html` is a subset of the current page, perhaps you can use selective print CSS and load the print dialog straight from there, meaning they cannot return to the actual `full-fat` page without closing the dialog. https://developer.mozilla.org/en-US/docs/Web/CSS/@media – Rob Schmuecker Jun 24 '15 at 18:07
  • @RobSchmuecker Sounds feasible, I'll try it! Thanks! – David Shen Jun 24 '15 at 18:34

0 Answers0