Use the DYNASCRIPT tag to add server-side ActiveX scripts to pages in a Host Publisher Web library. These scripts can:
You can use several languages to write scripts. The ActiveX scripting syntax varies by language. For specific information about syntax, refer to the documentation for the ActiveX scripting language you are using.
<DYNASCRIPT Language="language" {SESSIONED="True/False"}>
.
.
.
</DYNASCRIPT>
Note: The DYNASCRIPT tag requires a </DYNASCRIPT> end tag.
The following attributes apply to the DYNASCRIPT tag:
The languages you can use to write scripts in Host Publisher are dependent on the ActiveX scripting engines installed on a PageServer machine. If you have installed Microsoft Internet Explorer 3.x, the developer has access to the VBScript and JScript languages. Additional ActiveX scripting engines might be available for purchase from third-party vendors.
Note: JScript is the Microsoft implementation of the JavaScript scripting language. Although JScript is the Microsoft implementation name, the LANGUAGE= parameter must be JavaScript.
When the SESSIONED attribute is specified, the script has access to a Session object that enables scripts across multiple pages to store and retrieve values generated by previous pages and scripts.
The DYNASCRIPT tag provides access to the following objects:
The Session object stores key-and-value parameter pairs specified by the developer. This object is unique, because its values remain in place between accesses to Host Publisher pages by the same user. Every user has a unique Session object.
The SESSIONED attribute and session data for the DYNASCRIPT tag maintain data beyond a single page. You must define session data for the page. You can reference the session variable any number of times until the session object time-out expires. The session object time-out default is 10 minutes from the last time the user accesses the session object.
Each parameter pair has a key and a value.
For examples of how to use the Session object, refer to the examples under Session data and Document object examples.
Note: Many of the methods return a string upon success or an empty object upon failure. In JavaScript, you can test for the empty object by comparing the return value to null. In VBScript, the empty object can be tested for by comparing it to " ". Unfortunately, there is no way to distinguish between this case and the successful return of an empty string in VBScript.
Use the Registry Editor to change the session data time-out.
After you have defined session data using DYNASCRIPT statements, any subsequent page or SIM that supports session data can refer to the data. However, before the session data can be used, the page with the DYNASCRIPT SESSIONED attribute must be accessed by a client.
You can enter session data in the following SIMs:
In the |
Use the |
To |
ODBC SIM |
Enter SQL and the Edit SQL tabs Select Statement text box |
Type:[property name] |
ActiveX SIM |
Method dialog box, From box |
SelectSession Variable |
Java SIM |
Parameter dialog box |
SelectPass the value of a single session value |
Host Access SIM |
Macro editor |
Type:[property name] |
The document object is an object reference to the document the PageServer is generating. Scripts can write content into the current document and the client sees the data.
VBScript syntax:
<DYNASCRIPT Language=VBScript>
Document.Write("Write out some document text")
</DYNASCRIPT>
JScript syntax:
<DYNASCRIPT Language=JavaScript>
Document.Write("Write out some document text");
</DYNASCRIPT>
Attention: Do not use the .WBL extension with the name of the library (TestLibrary).
VBScript syntax using a function:
<DYNASCRIPT Language=VBScript>
Dim MyResult
MyResult=Document.Include("TestLibrary", "TestBook", "TestPage")
</DYNASCRIPT>
VBScript syntax using a subroutine:
<DYNASCRIPT Language=VBScript>
Document.Include "TestLibrary", "TestBook", "TestPage"
</DYNASCRIPT>
JScript syntax:
<DYNASCRIPT Language=JavaScript>
Document.Include("TestLibrary", "TestBook", "TestPage");
</DYNASCRIPT>
If the SESSIONED attribute is specified, a script can set session variables using commands such as:
VBScript syntax:
<DYNASCRIPT Language=VBScript SESSIONED=true>
Session.SetProp "Property1", "Persistent Data for Property One"
Session.SetProp "Property2", "Persistent Data for Property Two"
</DYNASCRIPT>
JScript syntax:
<DYNASCRIPT Language=JavaScript SESSIONED=true>
Session.SetProp("Property1", "Persistent Data for Property One");
Session.SetProp("Property2", "Persistent Data for Property Two");
</DYNASCRIPT>
A script can retrieve those value on another page by using syntax such as:
VBScript syntax:
<DYNASCRIPT Language=VBScript SESSIONED=true>
Document.Write(Session.GetProp("Property1"))
Document.Write(Session.GetProp("Property2"))
</DYNASCRIPT>
JScript syntax:
<DYNASCRIPT Language=JavaScript SESSIONED=true>
Document.Write(Session.GetProp("Property1"));
Document.Write(Session.GetProp("Property2"));
</DYNASCRIPT>
Unless you specify the SESSIONED attribute, the Session object is not available in the context of the script.
The environment object contains information about the request for the current page. Its properties enable access to information about the current page's URL and query parameters.
Note: The names of these properties are case sensitive.
Environment.URL contains the value of the URL for the current page. It does not contain any parameters associated with the URL.
Environment.PARAMS refers to key-and-value parameter pairs mapping to the query parameters passed by the client when the current page was requested. In the Web environment, this gives access to Web form selections.
Environment.PARAMS can list all the parameter pairs, even if you do not know the value of the keys.
Environment.PARAMS can store more than one pair with the same key. Scripts using Environment.PARAMS can work with multivalued parameters, such as those produced by a group of check boxes.
Note: Many of the Environment.PARAMS methods return a string upon success or an empty object upon failure. In JavaScript, you can test for the empty object by comparing the return value to null. In VBScript, the empty object can be tested for by comparing it to " ". Unfortunately, there is no way to distinguish between this case and the successful return of an empty string in VBScript.
In the examples, the following URL is sent from the client to the PageServer:
http://www.company.com/HostPublisher/library/book/page.htm?OS=nt&Version=4.0
VBScript syntax:
<DYNASCRIPT Language=VBScript>
urlname = Environment.URL
SystemType = Environment.PARAMS.GetProp("OS")
SystemVersion = Environment.PARAMS.GetProp("Version")
</DYNASCRIPT>
JScript syntax:
<DYNASCRIPT Language=JavaScript>
urlname = Environment.URL;
SystemType = Environment.PARAMS.GetProp("OS");
SystemVersion = Environment.PARAMS.GetProp("Version");
</DYNASCRIPT>
As a result, the following variables are set to these values:
The following examples demonstrate a simple page that does some form validation and lists the chosen values from a group of check boxes.
VBScript syntax:
<form action=_THIS method=POST>
Name: <INPUT TYPE=TEXT SIZE=20 NAME="UserName"><BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Chess"> Chess<BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Gardening"> Gardening<BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Horseback Riding"> Hoseback Riding<BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Quilting"> Quilting<BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Skiing"> Skiing<BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Video Games"> Video Games<P>
<INPUT TYPE=SUBMIT VALUE=OK>
</FORM>
<HR>
<DYNASCRIPT LANGUAGE=VBSCRIPT>
NumHobbies = Environment.PARAMS.GetNumValues("Hobbies")
UserName = Environment.PARAMS.LookupOne("UserName")
if NumHobbies = 0 then
Document.Write("Please Select Some Hobbies.")
elseif UserName = "" then
Document.Write("Please Enter a Name.")
else
Document.write(UserName + ", you selected the following Hobbies. <br>")
REM List all the hobbies
for HobbyIndex = 0 to NumHobbies - 1
Hobby = Environment.PARAMS.GetKeyValue("Hobbies", HobbyIndex)
Document.Write(CStr(HobbyIndex + 1) + ". " + Hobby + "<br>")
next
end if
</DYNASCRIPT>
JScript syntax:
<form action=_THIS method=POST>
Name: <INPUT TYPE=TEXT SIZE=20 NAME="UserName"><BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Chess"> Chess<BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Gardening"> Gardening<BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Horseback Riding"> Hoseback Riding<BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Quilting"> Quilting<BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Skiing"> Skiing<BR>
<INPUT TYPE=CHECKBOX NAME="Hobbies" VALUE="Video Games"> Video Games<P>
<INPUT TYPE=SUBMIT VALUE=OK>
</FORM>
<HR>
<DYNASCRIPT LANGUAGE=JAVASCRIPT>
NumHobbies = Environment.PARAMS.GetNumValues("Hobbies");
UserName = Environment.PARAMS.LookupOne("UserName");
if (NumHobbies == 0)
Document.Write("Please Select Some Hobbies.");
else if (UserName == "" || UserName == null)
Document.Write("Please Enter a Name.");
else
{
Document.write(UserName + K ", you selected the following Hobbies. <br>");
// List all the hobbies
for (HobbyIndex = 0; HobbyIndex < NumHobbies; HobbyIndex++)
{
Hobby = Environment.PARAMS.GetKeyValue("Hobbies", HobbyIndex)
Document.Write((HobbyIndex + 1) + ". " + Hobby + "<br>")
}
}
</DYNASCRIPT>
If you do not specify a field name after PARAMS, all form parameters after the ? are passed. The string is in the undecoded form sent by the Web browser.
In the examples, the following URL is sent from the client to the PageServer:
http://www.company.com/HostPublisher/library/book/page.htm?OS=nt&Version=4.0
VBScript syntax:
<DYNASCRIPT Language=VBScript>
urlname = Environment.URL
SystemType = Environment.PARAMS
</DYNASCRIPT>
JScript syntax:
<DYNASCRIPT Language=JavaScript>
urlname = Environment.URL;
SystemType = Environment.PARAMS;
</DYNASCRIPT>
As a result, the following variables are set to these values:
urlname = http://www.company.com/HostPublisher/library/book/page.htm
SystemType = OS=nt&Version = 4.0
The Environment.HEADERS object contains the HTTP headers passed with the request for the current page. Using Host Publisher with a Web server point of entry, these headers are actually the headers that the HTTP browser passed when requesting the page.
The methods available with Environment.HEADERS are the same as those available with Environment.PARAMS. Here, the key-and-value parameter pairs refer to header names and header values, rather than query parameter names and values.
Note: Many of the Environment.HEADERS methods return a string upon success or an empty object upon failure. In JavaScript, you can test for the empty object by comparing the return value to null. In VBScript, the empty object can be tested for by comparing it to "". Unfortunately, there is no way to distinguish between this case and the successful return of an empty string in VBScript.
The following example displays all the HTTP request headers that were passed during the request for the current page.
JScript syntax:
<h3>Here are the headers your browser sent:</h3>
<dynascript language=javascript>
Headers = Environment.HEADERS;
NumHeaders = Headers.GetNumPairs();
for (i=0; i < NumHeaders; i++)
{
Document.Write(Headers.GetPairKey(i) + " = " + Headers.GetPairValue(i));
Document.Write("<br>");
}
</dynascript>
To pass headers back to the Web browser, add header keys to the Environment.OUTHEADERS object. Any headers added to this object are added to the HTTP response headers. Using Host Publisher with a Web server point of entry, these headers are sent back to the Web browser.
The methods available with Environment.OUTHEADERS are the same as those available with the Session object.
Pages that are cached by the PageServer do not include the OUTHEADER information. If the page is read from the PageServer cache, the response does not include OUTHEADER information. When using the OUTHEADER property, deactivate page caching for that page.
Note: Many of the Environment.OUTHEADERS methods return a string upon success or an empty object upon failure. In JavaScript, you can test for the empty object by comparing the return value to null. In VBScript, the empty object can be tested for by comparing it to " ". Unfortunately, there is no way to distinguish between this case and the successful return of an empty string in VBScript.
The IObjects object gives DYNASCRIPT access to a global object representing the integration objects.
The following DYNASCRIPT example lists all the values for the "ENGLISH" and "SPANISH" items in an integration object named "numbers."
JScript syntax:
<DYNASCRIPT language=javascript>
var numbers = IObjects.Get("numbers");
var bMore = true;
while (bMore)
{
Document.Write(numbers.GetItem("ENGLISH")
+ ", " + numbers.GetItem("SPANISH") + "<br>");
bMore = numbers.NextRow();
}
</DYNASCRIPT>
The Alias object gives access to the URL aliases set up for the current Web library (WBL).
The server object is used to create instances of other OLE servers for use within the script.
The following example instantiates an instance of Microsoft Excel, which can be used for accessing contents of spreadsheets or setting values passed from Web browsers into spreadsheets for calculation purposes. Any of the methods available within Excel can be accessed through the object returned by Server.CreateServerObject. This sample also uses the IObjects scripting object.
JScript syntax:
<DYNASCRIPT LANGUAGE=JavaScript SESSIONED=true>
z = IObjects.Get("MCATSearchby");
res = z.GetItem("results");
var Excel=Server.CreateServerObject("Excel.Application");
Excel.Workbooks.Open("C:\\temp\\Book1.xls");
Excel.Worksheets("Sheet1").Activate;
Excel.ActiveSheet.Range("A1").Value =res;
Excel.Workbooks.Close;
Excel = null;l
</DYNASCRIPT>