3

Question: From Page A I have a link to Page B, on Page B it calls window.print() on load, which opens the print preview modal. My question is on Page A, is there an easy way to know that the print preview modal on Page B is currently open or not? (I only need this to work on Chrome)

Background: The reason I need to get this done is that there's a problem with Google Chrome blocking parent page's Ajax calls when it has child page who has print preview modal open. Related Questions:

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

https://code.google.com/p/chromium/issues/detail?id=139706

There's no easy way to completely solve the problem, so I only want to know whether the print preview modal is open and warn users to close the print modal on Page B before moving forward on Page A.

Community
  • 1
  • 1
Arch1tect
  • 4,128
  • 10
  • 48
  • 69

1 Answers1

1

This looks to not be possible. Chrome doesn't just blocks ajax execution, but it also stops processing all scripts on page A.

I think your best bet is to have instructions on page B for the user to print the page. Any Javascript initiated print will pause Javascript execution on page A.

A possible solution would be to display a message on page A before opening page B in anticipation of this behavior.

Edit: pulling in information from comment below

After further thinking, the best solution would be: On page B, in the script, that calls window.print(), just before calling print, send information back to page A communicating that this is going to take place, so that page A may take the appropriate action.

kcollins02
  • 81
  • 5
  • 1
    I don't think all scripts are stoped, I think it only blocks the Ajax calls. For example, I have a button on parent page, when I click it, it fires alert(). The button is still working despite print modal open on child page. – Arch1tect Jun 25 '15 at 19:16
  • I see what you mean, so maybe not all scripts. But In my tests, any interval or timeout scripts are paused in addition to the ajax calls. What about on page B, in the script, that calls window.print(), just before calling print, send information back to page A communicating that this is going to take place, so that page A may take the appropriate action. – kcollins02 Jun 25 '15 at 20:09