I am looking to enhance the print page functionality on my website. Currently, when the print icon in the footer is clicked, it opens the printer dialog box directly. I would like to change this behavior so that when the Print icon is clicked, the contents of the current page open in a new window with its own header and footer. In this new window, there should be a "Print" button located in the header. Clicking on this "Print" button should then trigger the opening of the print dialog box.
Thus far, I have been able to open a new window upon clicking the Print icon using the code below:
var printLinks = {};
printLinks.initialize = function() {
$('body').on('click', '.js-print-link', function(e) {
myWindow = window.open('', '_blank', 'resizable,scrollbars,status');
myWindow.document.write("<p>Test</p>");
myWindow.document.close();
myWindow.focus();
e.preventDefault();
});
};
However, I am encountering an issue where the content of the current page is not displayed in the new window. What should I include in the document.write() method instead of "Test"? Any assistance would be greatly appreciated.