简体   繁体   中英

How to detect print preview modal open in child page?

Question: From Page AI 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM