I have a scenario where in my webpage i do a window.open() which opens up another window whose onLoad()
invokes window.print()
. In this flow, the parent window
remains frozen disallowing any links to be clicked on. How to I get away with this problem?
For example:
An HTML page has three links: create, manage and print. The javascript code for the print link is the following:
var url = '/actions/print/';
var win = window.open(url,"Title_","resizable=yes,scrollbars=yes,directories=no,titlebar=no,location=no,status=no,menubar=no,width="+width+",height="+height);
now, the HTML rendered by /actions/print
is:
<html><body onload="window.print();"> ... Content goes here ...</body></html>
So as you can see, clicking on print opens up a new window and triggers print immediately. In this state, when i go back to parent window with three links and try to click on other links, it doesn't work and appears frozen.
I have a scenario where in my webpage i do a window.open() which opens up another window whose onLoad()
invokes window.print()
. In this flow, the parent window
remains frozen disallowing any links to be clicked on. How to I get away with this problem?
For example:
An HTML page has three links: create, manage and print. The javascript code for the print link is the following:
var url = '/actions/print/';
var win = window.open(url,"Title_","resizable=yes,scrollbars=yes,directories=no,titlebar=no,location=no,status=no,menubar=no,width="+width+",height="+height);
now, the HTML rendered by /actions/print
is:
<html><body onload="window.print();"> ... Content goes here ...</body></html>
So as you can see, clicking on print opens up a new window and triggers print immediately. In this state, when i go back to parent window with three links and try to click on other links, it doesn't work and appears frozen.
Share Improve this question edited Dec 1, 2015 at 21:03 Marco Bonelli 69.4k21 gold badges126 silver badges145 bronze badges asked Nov 23, 2015 at 20:08 SripaulSripaul 2,2359 gold badges37 silver badges61 bronze badges 3-
2
You can try using a timeout?
window.setTimeout(function(){window.print();},0);
Tell me if it works :) – www139 Commented Dec 1, 2015 at 4:18 - @Sripaul So, did my answer help you in any way? – redrum Commented Dec 3, 2015 at 21:40
- @www139, it didn't works; jsfiddle/stanimirsp5/a761hu2s/2 – stanimirsp Commented Jan 31, 2020 at 8:18
1 Answer
Reset to default 18 +25You can't resolve this issue on OS X. Which I am pretty sure you only tested on.
Here is how I came to that conclusion after testing on different browsers and plateforms.
Chrome, Safari and Firefox on OS X did not allow interactivity with parent window when a print modal was opened from a child window (closing the print dialog, but not the pop up, re-enabled interactivity).
IE8 on Win XP, IE11, Chrome and Firefox (all on Win7) always allowed interactivity with this same scenario.
This led me to believe this was an OS X restriction or remendation. On further research, here is what I found on developer.apple., confirming my doubts:
A document-modal dialog prevents the user from doing anything else within a particular document. The user can switch to other documents in the app and to other apps. Document-modal dialogs should be sheets, which are described in Using Document-Modal Dialogs (Sheets).
Use a sheet when multiple documents can appear in a single window at different times. For example, a tabbed browser can display different documents in a single window at different times. A sheet is appropriate in this situation, even though it applies to only the document that is currently visible in the window. Because users must in effect dismiss the current document before viewing a different document in the same window, they should first dismiss the sheet.
https://developer.apple./library/mac/documentation/UserExperience/Conceptual/OSXHIGuidelines/WindowDialogs.html