APPLICATION DESIGN


Adding JavaScript header information
Use the JS Header event to store any JavaScript(TM) functions that you want to call from other events on the page or form. You do not have to include the <SCRIPT> tags. IBMR LotusR Domino(TM) creates those for you and puts the script into the <HEAD> tag of the HTML page or form.

To add JavaScript header information

1. In the Programmer's pane, click the Objects tab.

2. Select the "JS Header" event.

3. Enter script in the Script area.

4. Click the green check mark to validate your work.

Example: Adding JavaScript header information

This example uses JavaScript(TM) 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.

Note The actual expiration date in the code has to be changed to a future date in order to make the cookies work properly.

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:


See Also