I am trying to make a copy of a page in its existing state, launch it in a new window, and have the listeners remain functional. Ultimately, I want to clone a portion of the page only, but for now I'm just trying to get it to work with the entire page.
I have the following function:
function clonePage() {
var printWindow = window.open(''),
html = $('html').clone(true, true);
printWindow.document.write("<!DOCTYPE html><html><head></head><body></body></html>");
$(printWindow.document).find('html').replaceWith(html);
}
What happens when I run this is if I click on something with a listener in the new window it affects the page in the old window.
I created a codepen to exemplify the problem. If you click on the Clone Me button and then the Alert button on the new window, the alert is displayed on the parent window.