Adding JavaScript™ header information
About this task
Use the JS Header event to store any JavaScript™ functions that you want to call from other events on the page or form. You do not have to include the <SCRIPT> tags. Domino® creates those for you and puts the script into the <HEAD> tag of the HTML page or form.
To add JavaScript™ header information
Procedure
- In the Programmer's pane, click the Objects tab.
- Select the "JS Header" event.
- Enter script in the Script area.
- Click the green check mark to validate your work.
Example: Adding JavaScript™ header information
About this task
This example uses JavaScript™ and cookies to load a page or form into the browser and save a cookie called "Cookie_Man" in the user's cookie file. It also displays a message that shows the number of times a user has visited the site. It uses two functions, doCookie() and getTimes(), written in the JS Header. These functions are called from the onLoad event.
In the JS Header Event enter the following code:
cookieName = "Cookie_Man";
function doCookie() {
var index = -1;
if(document.cookie) {
index = document.cookie.indexOf(cookieName);
}
if (index == -1) {
document.cookie = cookieName +
"=1; expires=Saturday, 03-Apr-2010 08:00:00 GMT";
} else {
var countbegin = document.cookie.indexOf("=", index) + 1;
var countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length
}
var count = eval(document.cookie.substring(countbegin, countend)) + 1;
document.cookie=cookieName+"="+count+"; expires=Saturday, 03-Apr-2010 08:00:00 GMT";
}
}
function getTimes() {
if(document.cookie) {
var index = document.cookie.indexOf(cookieName);
if (index != -1) {
var countbegin = document.cookie.indexOf("=", index)+ 1;
var countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
return document.cookie.substring(countbegin, countend);
}
}
return 0;
}
The onLoad page or form event contains the following code:
doCookie(); // Grab the cookie information
document.forms[0].visited.value = getTimes(); // format visited count into the document
Create a text field on the form named "Visited."
Include the text on the form:
You have visited this site <Visited> time(s) before.