Latest web development tutorials

HTML DOM metodo close ()

Document Object Reference Document Object

Definizione e utilizzo

metodo close () viene utilizzato per chiudere la finestra del browser.

grammatica

document.close()


Supporto per il browser

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Tutti i browser principali supportano metodo close ()


Esempi

esempio 1

Aprire un flusso di output, aggiungere del testo, e quindi chiudere il flusso di uscita:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function createDoc(){
    var doc=document.open("text/html","replace");
    var txt="<!DOCTYPE html><html><body>学习 HTML DOM 很有趣!</body></html>";
    doc.write(txt);
    doc.close();
}
</script>
</head>

<body>
<input type="button" value="新文档" onclick="createDoc()">
</body>
</html>

Prova »

esempio 2

Aprire il flusso di uscita (si apre una nuova finestra; about: blank), aggiungere testo, e quindi chiudere il flusso di uscita:

<html>
<body>

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

</body>
</html>

Prova »


Document Object Reference Document Object