Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Chrome print using system settings

  • Thread starter Thread starter Deleted member 2829
  • Start date Start date
D

Deleted member 2829

Guest
I am creating and printing a window in JavaScript with this code
JavaScript:
var w = window.open("about:blank", "Print", "width=800,height=800");
w.document.write(html);
w.print();
w.close();

which works fine. The window comes up with the Chrome print screen on top of it. Both buttons Print and Cancel do their job and then the window disappears as expected. So far so good !! But as always there is a snag.
The Chrome print screen also has an option "Print using system dialog" which I want to use if I want to print with different printer settings. When I click that option, I briefly see the Windows native print dialog pop up, and then the whole stack (my created window, the Chrome print window, and the Windows print dialog) is closed. I don't get a chance to print.

I tried fixing this by adding an onafterprint even handler to the body of the printed window, and in that handler have the window close itself. But that runs into the same problem - the event handler fires when I click "Print using system dialog". It's as if Chrome is saying "Ok, Windows will handle it from here, I'm done, bye !". Perhaps that makes sense from Chrome's point of view, but it's quite a conundrum as I can't close my window before the Windows print dialog starts and completes the printing, and I have no way of knowing when that will be done.

Any ideas would be much appreciated.
 
I am creating and printing a window in JavaScript with this code
JavaScript:
var w = window.open("about:blank", "Print", "width=800,height=800");
w.document.write(html);
w.print();
w.close();

which works fine. The window comes up with the Chrome print screen on top of it. Both buttons Print and Cancel do their job and then the window disappears as expected. So far so good !! But as always there is a snag.
The Chrome print screen also has an option "Print using system dialog" which I want to use if I want to print with different printer settings. When I click that option, I briefly see the Windows native print dialog pop up, and then the whole stack (my created window, the Chrome print window, and the Windows print dialog) is closed. I don't get a chance to print.

I tried fixing this by adding an onafterprint even handler to the body of the printed window, and in that handler have the window close itself. But that runs into the same problem - the event handler fires when I click "Print using system dialog". It's as if Chrome is saying "Ok, Windows will handle it from here, I'm done, bye !". Perhaps that makes sense from Chrome's point of view, but it's quite a conundrum as I can't close my window before the Windows print dialog starts and completes the printing, and I have no way of knowing when that will be done.

Any ideas would be much appreciated.
How about setting a timer on the window?
 
How about setting a timer on the window?
Well, it's an option - although a terrible one IMO..... While choosing printer parameters you might get distracted, spend some time elsewhere, and come back to find your work gone because the timer fired and closed the whole shebang. Then I would prefer NOT to close the window and be obliged to close it manually each time. But that is very annoying. Perhaps I'll go back to my earlier setup to use the current window instead of creating a new one. But that is not without its intricacies either.
Dang, how hard can it be just to print something without hassle !
 
Well, it's an option - although a terrible one IMO..... While choosing printer parameters you might get distracted, spend some time elsewhere, and come back to find your work gone because the timer fired and closed the whole shebang. Then I would prefer NOT to close the window and be obliged to close it manually each time. But that is very annoying. Perhaps I'll go back to my earlier setup to use the current window instead of creating a new one. But that is not without its intricacies either.
Dang, how hard can it be just to print something without hassle !
Granted, adding timers isn't THEE best option when it comes to performance, you could also use it in tangent with storing whatever data you currently have to storage, and if it closes down before you are able to use that data, you can set something up to where you are prompted if you would like to continue with last session, and go from there.
 
I am not too worried about performance in this case, or about losing whatever I was doing in the printer preferences. An autosave and restore option seems gross overkill, and I don't think I could even do it as it's Windows in charge at that time and Chrome evidently thinks it's done. l'll see if Firefox or Edge behave a bit better. Using another browser for this particular app is a valid option, although I don't like taking the easy way out.
 
Back
Top Bottom