Share this page 

Read an HTML page from the server in a variableTag(s): Language

[N4 or better]
<SCRIPT LANGUAGE= "JavaScript1.2">
function getPage() {
  // the file to be read
  pageURL = new

  // step 1, open the URL
  var openConnection = pageURL.openConnection;
  theConnection = openConnection()

  // step 2, connect to server
  var t=theConnection.connect

  // step 3, read the file using HTTP protocol
  var getContent = theConnection.getContent
  var theURLStream = getContent()

  // step 4, get an handle and fetch the content length
  var readStream =
  var gcl = theConnection.getContentLength
  gcLen = gcl()

  // and finally, read into a variable
  theText =""
  for (i = 1; i <gcLen; i++) {
   theText += new java.lang.Character(readStream())

  // for demonstration

<INPUT TYPE="button" VALUE="get page" onClick="getPage();">
After pressing the button, wait a few seconds while the page is read, then an Alert box containing the page content will appear, if the Alert box is bigger (probably) than the screen, just press ENTER to close it.

The above HowTo is for Netscape.

With IE, we can load the page in hidden frame and then get its content with

var sContent = document.all(0).innerHTML;
You can save / restore the body and not the whole document by using
where you have given the body an 'id' attribute of "content".

See also this related HowTo