I want to create another window when user clicks open button. This window will contain contents if a div. Also it'll have a close button. On click of the close button I want to close this popped up window.
When we click on open it opens the <div id="myContent">
in another window, but after opening it, I want it to close that window using close button.
document.getElementById("mybtn").addEventListener("click", function() {
var newWindowContent = document.getElementById("myContent").innerHTML;
var newWindow = window.open("", "", "width=500,height=400");
newWindow.document.write(newWindowContent);
});
<article type="text" id="editor" contenteditable="true">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatum ad eos, facere ipsam odio dignissimos voluptatibus dolor sunt qui ipsum, quos praesentium doloribus nulla mollitia laboriosam expedita maxime, asperiores consequuntur?
</article>
<h1>Open the element content when click the button</h1>
<div id="myContent">
<button id="mybtnn">close</button> This is the content that will be inside the new popup window
</div>
<button id="mybtn">open</button>