Welcome to my new page. This page has new title (look at the top of the browser) and of, course, completely new content.

It loads faster than a reload of the browser and it is even full of interesting things.

You can even return to the old page

')} //-->

Writing a new page after loading

Writing with JavaScript 2

This page was written many years ago. What I tried to do in these pages is now easy using W3C DOM. See this page. This page is of historical interest only!

Click the button above and see what happens.

The document.write is used after loading the page and completely obliterates the code for this page and writes some of its own. Whilst you can write stuff in a page before the document stream has closed, you cannot add stuff after it has closed. Using document.write after loading, obliterates the original page.

We use a function that we load after the page has loaded. So all we get is the stuff in the document.write.

The code in the HEAD is shown below:

<script type="text/javascript">


function newPageWriter(){

document.write('<html><head><title>My New Page</title><meta name="keywords" '+

'content="MY FILE"><meta name="description" content="MY FILE" />'+

'<meta name="JAVASCRIPT GENERATOR" content="jsEditor" /></head>'+

'<body bgcolor="#FF8000">'+

'<h1>Welcome!</h1><p>Welcome to my new page. This page has new title (look at the top of the browser) '+

'and of, course, completely new content.</p><p>It loads faster than a reload of the browser and it full '+

'of interesting things.<p>You can even return to the old page<p><form name="" '+

'method="post" action="" enctype="text/plain"><input type="button" '+

'value="GO BACK TO ORIGINAL PAGE" onclick="history.go(-1)" /><br /></form></body></html>')




  The above code is a document.write within a function called newPageWriter(). We call this function when we click on the form button. Here's the code for the form button:

<form method="post" action enctype="text/plain">


<input type="button" value="Click Me" onclick="newPageWriter()" />

<br />



All this does is call the function.

So, to write to a page after it has loaded, then use the above code. You create a function containing a document.write and then some way of calling it, such as with a form button. When document.write is activated, it overwrites all the code in the page. And you get a completely new page which loads faster than a reload of the original document.

However, sometimes, we might prefer to add text to the document after it has loaded without obliterating the original text.

Let's look at this now.

Next: Writing to an already loaded document without obliterating the original code.

Ken Ward's HTML Guide...


[If you need to learn more about HTML visit the HTML Tutorial]