|
January 14, 2002 Saving Cookies in Persistent Related Menus Tips: January 2002
Yehuda Shiran, Ph.D.
|
|
One of the problems of related menus is that once you go off to another Web page and then come back, the menu selections are not persistent. You can overcome this problem with cookies. The cookie property belongs to the document object. Play around with these related menus:Write down the entries you see on both menus. Let's assume that the left and right menus are level2 and level23, respectively. Surf now to another Web site of your choice. Hit the browser's Back key. You will see that both menus persisted. The left menu will be level2 and the right menu will return to level23.
The trick is to save the menu index in a cookie whenever it changes, and restore the cookie upon the page's reloading. We save the cookie when the right menu (
We save the right menu index only. We name our persistent variable as listSelectedIndex. Its value is document.forms[0].list.selectedIndex. Tomorrow, we'll show you how to retreive this cookie and index.
People who read this tip also read these tips: Look for similar tips by subject: |