Latest web development tutorials

HTML DOM método close ()

Document Object Reference Document Object

Definição e Uso

método close () é usada para fechar a janela do navegador.

gramática

document.close()


Suporte a navegadores

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Todos os principais navegadores suportam método close ()


Exemplos

exemplo 1

Abra um fluxo de saída, adicione algum texto e, em seguida, fechar o fluxo de saída:

<!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>

tente »

exemplo 2

Abra o fluxo de saída (abre uma nova janela; about: blank), adicione o texto, e, em seguida, fechar o fluxo de saída:

<html>
<body>

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

</body>
</html>

tente »


Document Object Reference Document Object