capt webb
Capt. Horatio T.P. Webb
Pages On-The-Fly
Parks -- Fall 2017

Version 1 --- Last Updated 8:30 AM 10/9/2017

It is possible from javascript to create a new page and replace the current one without having to go to the web for a new page. This process is relatively easy to do and requires only three javascript methods:

  1. document.open();

    This method sets the javascript to write new HTML to the current page (i.e., the document)

  2. document.write (string of HTML );

    This method is used to place new HTML on the current page. It replaces the existing HTML page.

    Typically there may have to be several document.write statements to completely specify the new page. But only one is required.

    Most often the programmer should include:

  3. document.close();

Suppose we wish to replace this page with a "Hello World" page. Assume the code that is to be executed is in a javascript function named:

write_new_page( ).

The javascript would be:

 
function write_new_page()
{
 document.open();
 document.write ("<HTML><BODY>");
 document.write "<table border='1'><tr><td><img src='captsm.gif'></td>"
 document.write "<td>Hello World</td></tr></table></BODY></HTML>");
 document.close();
 }