<!DOCTYPE html> <html> <body> <h1>Document 对象</h1> <h2>open() 和 close() 方法</h2> <p>单击“打开”在新窗口中打开文档,向其中写入一些文本并关闭它:</p> <button onclick="myFunction()">打开</button> <script> function myFunction() { const myWindow = window.open(); myWindow.document.open(); myWindow.document.write("<h1>Hello World!</h1>"); myWindow.document.close(); } </script> </body> </html>