To print a page that isn't showing you need to use an old hack, hidden iframes.
If you place an "onload" call to window.print() on the page you want to print you can then simply have your button trigger a hidden iframe (1x1) to load that page. Your browser will block any XSS attempt so the javascript to cause a print operation needs to be on the page that is loaded.
Alternatively the child page can usually also access the parent page (as long as they are on the same domain) so you could also have the hidden child page available the entire time (but hidden) and have it register a click event listener on the parent page.
htmlwhen you click the print button.