HTML DOM close() 方法


定义和用法

close() 方法用于关闭浏览器窗口。

语法

  1. document.close()

浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 close() 方法

实例

实例 1

打开一个输出流,添加一些文本,然后关闭输出流:

  1. <html>
    <head>
    <script>
    function createDoc()
      {
      var doc=document.open("text/html","replace");
      var txt="<html><body>Learning about the HTML DOM is fun!</body></html>";
      doc.write(txt);
      doc.close();
      }
    </script>
    </head>

    <body>
    <input type="button" value="New document" onclick="createDoc()">
    </body>
    </html>
运行一下 »

实例 2

打开输出流 (新窗口打开; about:blank),添加文本,然后关闭输出流:

  1. <html>
    <body>

    <script>
    var w=window.open();
    w.document.open();
    w.document.write("<b>Hello World!</b>");
    w.document.close();
    </script>

    </body>
    </html>
运行一下 »