How to detect print preview modal open in child page?

时间:2015-06-25 18:22:11

标签: javascript jquery html ajax google-chrome

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.

1 个答案:

答案 0 :(得分: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.