<html>
<head>
<script type="text/javascript">
function createNewDoc()
{
var new_doc = document.open("text/html","replace");
var txt = "<html><body>这是新的文档</body></html>";
new_doc.write(txt);
new_doc.close();
}
</script>
</head>
<body>
<button onclick="createNewDoc()">点击写入新文档</button>
</body>
</html>
运行该例子,点击按钮,页面内容会被替换。查看网页源代码,依然是原来的饿,但用 Chrome 等浏览器查看网页元素,已经是被替换后的内容了。