For Netscape users, there is a file in the c:\netscape directory called cookies.txt. Explorer uses a directory to store this data, in c:\winnnt\cookies or c:\windows\cookies. Many web pages use this file to store information to store session variables, or to determine if a user is new to a web site.
The file is handled similar to the way an INI file is accessed, except that cookie data has an "expiration date".
All operations to the cookies file are not written to the hard disk until the browser is closed. This is transparent to any functions that use the cookies file.
Each element in the file has a keyword, expiration date, and value. To set a value in the file, a very specific format is needed. Getting a value from this file involves parsing out each line until the desired element is found.
A set of functions is available for accessing the cookies file.
Sets a value in the cookies file for the lable specified. Null can be
used in place of the expiration date if the access is session-specific.
Example: f_setcookie("username","jake",null);
Returns the value from the cookies file for the value specified.
Example: cur_name = f_getcookie("username");
Here is the source code for the functions:
function f_getcookieval(offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); } function f_getcookie(name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) return f_getcookieval (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } function f_setcookie (name, value, expires) { document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())); }
Here is the main file, test1.htm:
<html> <head> <title>ttt</title> <script src="test2.js"> </script> </head> <form> <input type="button" value="Test Fn" onclick="f_test1()"> </form> </html>
Here is the include file, which contains a function:
function f_test1() { alert("Test1 function") }
When the button is pressed, the included function is called.
This error occurs when working with multiple browser windows within a javascript application. It seems to occur when the communication mechanism between the open windows fails, during a close operation. When an object containing a close call fails to work immediately, the "pure virtual call" GPF will occur if the object is clicked multiple times. If the object is clicked just once, the close operation will complete normally.
Two solutions to this problem are:
function f_exit() { document.links[4].href=""; parent.close(); }Destroy the current frame within the clicked event. This can be done by performing a write to the document, and closing it.
function f_exit() { document.write("Please wait ..."); document.close(); parent.close(); }
parent.fra_tttedit2.document.frm_tttedit2.sle_firstname.value="Sally";Note that the naming convention allows each level to be identified easily.
To access a function called
fra_tttedit2.f_checkname();Note that the form designation is not needed, since functions exist at the window level.
Setting focus to a default control allows the user to begin typing without having to use the mouse. In the following example, a listbox named "lb_cat" exists on form "frm_tttnew". The goal is to set focus to this control after the form is loaded. Here's how the end of the HTML file would look.
<script language="javascript"> <!-- //-------------------------------------------------------------------------- document.frm_tttnew2.lb_cat.focus() //-------------------------------------------------------------------------- // --> </script> </body> </html>Note that this code is after the form definition, and before the last HTML tag.
Passing variables in javascript works very similar to the PowerBuilder method.
When a window is opened, a variable is assigned to it. Using dot notation, a
variable within the window can be assigned a value. Note that the variable does
not have to be declared within the calling window; it is created
at runtime, just like all other javascript variables. Here is an example:
w_lookup = window.open("tttlu.html","w_tttlu", "toolbar=0,menubar=0,location=0,status=0,height=470,width=630") ; w_lookup.w_tttnew = parent; /* allow window to refer to this window */ w_lookup.asset_id = 12345; /* int value */ w_lookup.tnt_code = "NTRS"; /* char value */These three variables can be accessed within the window w_lookup, as follows:
newvar = asset_id ; w_tttnew.f_processcode(tnt_code);Note how the calling window's function is called.
Javascript statement can be created and executed using the eval function. This is similar to dBase's macro prefix. The eval function takes an argument as a string- this string can be a line of code, or a variable, or any piece of Javascript that could execute in the given context. Here is an example:
var myvar1=0 var myvar2=0 var myvar3=0 /* set all variables to 100 */ for (i=1;i<4;i++) { eval("myvar" + i + "=100"); }Here is another example, in which a function calls one of four different functions based on the parameter:
function f_sort(parm1) { eval("array1.sort(f_compare" + parm1 + ");"); eval("prev1=loc" + parm1 + "1;"); eval("prev1=loc" + parm1 + "2;"); }Using the eval function saved 9 lines of code in this case!.
When a user types into a text field and presses enter, different behaviors have been observed. When there is one text field on the form, the data disappears; when there are two fields on the form, the data stays in the fields (the expected behavior).
There are many instances when the typed in data needs to be processed by the form before sending to the server; this issue definitely impacts such cases.
Try the pages linked below, and note the odd behavior.
Form with one text field
Form with two text fields
Simple example depiciting use of a CGI counter.
Number of Hits: