Sử dụng document.open(), document.write(), document.close() để ghi đè toàn bộ nội dung trang.
Ví dụ
<!DOCTYPE html>
<html>
<body>
<p>Click để thay thế nội dung này.</p>
<button onclick="Display()">Replace</button>
<script>
function Display() {
document.open("text/html", "replace");
document.write("<p>Demo text!</p>");
document.close();
}
</script>
</body>
</html>