关闭窗口弹出按钮点击使用窗口打开()



我想在用户单击打开按钮时创建另一个窗口。这个窗口将包含内容,如果一个div。它也将有一个关闭按钮。点击关闭按钮,我想关闭这个弹出的窗口。

当我们点击打开时,它会在另一个窗口中打开<div id="myContent">
,但是在打开它之后,我希望它使用关闭按钮关闭该窗口。

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>

可以使用window.close

<button id="mybtnn" onclick="window.close()">close</button>

最新更新