Read an HTML page from the server in a variableTag(s): Language
[N4 or better]
<HTML>
<HEAD>
<SCRIPT LANGUAGE= "JavaScript1.2">
function getPage() {
// the file to be read
pageURL = new
java.net.URL
("http://www.yourserver.com/yoyrpage.html");
// step 1, open the URL
var openConnection = pageURL.openConnection;
theConnection = openConnection()
// step 2, connect to server
var t=theConnection.connect
t()
// 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 = theURLStream.read
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
alert(theText)
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT TYPE="button" VALUE="get page" onClick="getPage();">
</FORM>
</BODY>
</HTML>
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;
document.all("content").innerHTML
See also this related HowTo
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com