VB6 at Work: The Cookie Page VB Help

To store a string on the client computer’s system and access it from another page or to access it the next time the page is opened, use the Cookie property, as outlined in the Cookie page. The Cookie page, shown in Figure 21.8, is a revision of the Pagel page. This time we prompt the user for his or her name, and then we store it in the Document object’s Cookie property. The next time you open this
page, the user’s name appears automatically. To test the Cookie page, you must have a Web Server installed. Opening the Cookie page with Internet Explorer won’t do the trick. Cookies are saved on the client computer by the browser and only if they are furnished by a server. You can use any Web server, including the FrontPage Web server or the Personal Web Server.

I used the FrontPage Web server to test this example (which works just like the Personal Web’ Server). Here are the steps to follow to experiment with the COOkiE property:

1. Copy the Cookies.htm file from the CD to the Cookie folder under the Web server’s root folder.
2. Rename it to Index.htm.
3. Start the FrontPage Web server or any other server you have installed on your system (if it’s not already running).
4. Start Internet Explorer and connect to the following URL
The numerals constitute the IP address of the local server, and Cookie is the name of the folder to which the site has been copied (this site contains a single page).
5. When prompted, enter your name. The script displays it on the page and saves it in the Document object’s Cookie property.
6. Connect to another URL by entering it in the browser’s Address box .
7. Click Back to return to the Cookie page. This time you won’t be prompted for your name. It’s already stored in the Cookie property.

The Cookies.htm Document

The If structure of the script. examines the value of the Cookie property. If this property has no value.It prompts the user to enter a name. It then stores the name entered by the user in the Cookie property.The second time you connect to this page, the Cookie property has a value, and the Else clause executes, which assigns the cookie’s value to the UserName variable. The rest of the code is the same as that for the Pagel page, with the exception of the last Write method, which displays the current value of the cookie on the page. Using cookies in this way is slightly unorthodox. Cookies are usually stored as pairs of names and values, separated with a semicolon. A more reasonable cookie value is the following:

As you can see, you can store many variable values in the cookie, but there areno methods for retrieving the value of a single variable. You must read the entire cookie and then use the string manipulation functions (the InStrO, Midt), and other string manipulation functions) to isolate each pair and extract the name of
the variable and its value.

Cookies Expire

Anchor  Anchor is a property of the Document object, and like some other properties, it is also an object. The Length property of the Anchor object returns the number of anchors in the document. The individual anchors are stored in the Anchors array, whose elements can be accessed with an index. The name of the first anchor in the document is Anchors(O) (its value is the NAME attribute of the <A> tag that inserted the anchor in the document), Anchors(l) is the second anchor, and so on. The following statements display the number of anchors in the current document in a message box

Scanning the anchors of the current document from within the same document’s script section isn’t practical. But you can open another document in a frame and access the anchors of the frame with the Frame(l).Documenf Anchors array. For another example, see the DocumentLinks example, later in this chapter,

Link This property is similar to the Anchor property, but instead of presenting the anchors, it represents the hyperlinks in the current document. Like the anchors array, the links array is a property of the Document object, which is the only object that can contain links. The basic property of the Link object ~ the Length property, which returns the number of links in the document Each link is a member of the Links array. The first link is Links(O), the second ‘one is Links(l), and so on. Because the hyperlinks in a document are destinations, the Link object’s properties are identical to the properties of the Location object, but they are read only.

To obtain the number of links in the document displayed in the browser’s window, use the following statement

LastModlflecd Thisproperty returns the date the current document was last modified. You can use the lastModified property of the Document object to display the date and time it was last modified, without having to hardcode this information in the document itself

Referrer This property returns the URL of the referring document.

Posted on November 6, 2015 in Visual Basic and the Web

Share the Story

Back to Top