1

This may be a specific issue with Chrome that I should take to their forums, but I wanted to see if there was an alternate solution or a fix. We are using backbone.js for our single page app and to print, we create a new window, write our html to it and then call print on the new window. If a user closes the tab without closing the print dialog, the hashchange and popstate events do not fire anymore in the Backbone.History object. You can't refresh the page either. We have to close the page and reopen in a new tab to restart. This error does not occur on linux builds, just windows. If the user closes the print dialog first and then the tab, everything works normally.

The ideal solution would be for the hashchanges to keep working. If this isn't possible, is there another solution to do a print of a certain portion of HTML?

I've tried writing a script that calls window.print() in the new window but it does not fire or even throw an error. IFrames will not work because the css of the single page app will overwrite the printing portions html. Any solutions are welcome.

Here is a jsfiddle to show you the problem.

http://jsfiddle.net/5P4qv/3/

window.document.getElementById('run_print').onclick = function () {
    window.onhashchange = function () {
        console.log('hashchanged');
    };
    window.location.hash = 'test';
    windowObject = window.open("", "_blank");
    windowObject.document.open();
    windowObject.document.close();
    windowObject.focus();
    windowObject.print();
};

You may need to allow popups for this to work. Click the print button and the popup will open to the print dialog. Close the window without closing the print dialog and the original window will act as if it is still loading. You will not be able to refresh either. Again, this is only on Chrome in windows.

  • See the solution here http://stackoverflow.com/questions/23071291/javascript-window-print-in-chrome-closing-new-window-or-tab-instead-of-cancel – صفي Jun 19 '14 at 12:45

0 Answers0