User Guide

HTTPProvider Object 269
Sample HTTPProvider script
//**********************************************//
// ActiveScripting example (JScript)
//**********************************************//
// This script contacts the site specified by the user URL,
// copies its source code and displays the page in the internal
// browser of the application
//**********************************************//
function Main (){
var sDocName;
var sSource;
var sMessage;
with (Application){
if (HTTPProvider.State == 0){
// Set the URL property of HTTPProvider Object.
HTTPProvider.URL = InputBox(VersionText, "Please Enter the URL.",
"http://www.yahoo.com");
// Perform HTTP Get Request
HTTPProvider.Get();
sSource = ’’;
if (HTTPProvider.ReasonPhrase == "OK") // Check if the requested
URL can be displayed
sSource = HTTPProvider.ReceivedStreamAsString; //Save the page
source into the string
else{
sSource = ’<font size="+2" color="#0000ff" >’ //If the page
cannot be displayed, post error message and show a reason.
sSource = sSource + ’The request could not be completed:
<br><br><li>’
sSource = sSource + HTTPProvider.ReasonPhrase + ’.</font></
li>’;
}
sMessage = "The source of the requested page has been copied
successfully,\n";
sMessage = sMessage + ’the page now will be displayed ’;
sMessage = sMessage + ’in the browse window of \n’ + VersionText +
’!’;
MessageBox (sMessage, VersionText, 0);
}
else{
sSource = ’You are not connected to Internet properly, ’;
sSource = sSource + ’please check the connection and try again’;
}
MessageBox("Some images may not be downloaded properly!","Warning!",0);
NewDocument (false); // Initialize a new document.
ActiveDocument.InsertText(sSource, false); // Insert the received
source code into new document.
CurrentView = 2;// Change to the browse mode.
}
}