I know that this question has been asked before, but most answers only replaced the body tag, or needed jQuery. I want to be able to replace the entire page contents including the DOCTYPE using plain JavaScript. Also, I don't want to redirect the page with window.location.href
. Take this simple page (index.html):
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<p>Testing...</p>
</body>
</html>
After loading another page with AJAX:
var page;
var file = new XMLHttpRequest();
file.open('GET', './toload.html');
file.onreadystatechange = function() {
page = file.responseText;
}
file.send();
I want to erase my current page contents and display the contents of toload.html
, which is:
<!DOCTYPE html>
<html>
<head>
<title>Loaded</title>
</head>
<body>
<p>Hello. This page is now loaded!</p>
</body>
</html>
How can I do this?