Need help with my first batch of cookies
dframeli
Status: New User - Welcome
Joined: 08 Jan 2009
Posts: 1
Reply Quote
Please see the script shown below. This bit of code allows visitors to my intranet site to open and close the "left navigation bar".

(FYI, the presence of the left navigation bar is required by my IS department, however an alternate navigation method is being used and this "left navigation bar" is no longer needed, therefore I've added the code below as a way for visitors to hide the left navigation bar from view)

What I want to do is to record the status of the left menu bar (using a cookie) each time the left navigation bar is opened or closed, and then to use the value of that cookie as a way to save a returning visitors preferences.

1) At first, I want to check for the existance of the cookie "lnb_status".

2) If "lnb_status" doesn't exist, I want to create it and set the inital value to "open".

3) if "lnb_status" does exist, I want to read the value stored in the cookie and open the page with the left navigation bar toggled open or closed depending on the stored value in the cookie.

4) Afterwards, every time the left navigation bar is opened or closed, I want to update the value stored in the cookie so it can be read later by visitors returning to my site.

Only two values are possible, "open" and "closed". Expiration can be a very long time (365 days). My target browser is IE6 and IE7.

I know almost nothing about cookies, but I'll willing to learn. Can someone help get me started?

TIA!
Dale


:: Code ::

<script type="text/javascript">
//
// Show/hide left navigation
// <please do not post email addresses on web pages, email spam harvesters get them that way>
//
//document.getElementById('LeftNavigationAreaCell').style.display="none";
var ExpColl = document.createElement("TD");
ExpColl.innerHTML = '<DIV class="ms-pagemargin" onClick="Toggle(\'LeftNavigationAreaCell\');" style="cursorointer;"><IMG alt="Show menu" id="ToggleImage" src="/_layouts/images/plus.gif" /></DIV>';
document.getElementById('LeftNavigationAreaCell').parentNode.insertBefore(ExpColl,document.getElemen tById('LeftNavigationAreaCell'));
function Toggle(thisId)
{
if (document.getElementById(thisId).style.display=="none")
{
document.getElementById(thisId).style.display="";
document.getElementById("ToggleImage").src = "/_layouts/images/minus.gif";
document.getElementById("ToggleImage").alt="Hide menu";
}
else
{
document.getElementById(thisId).style.display="none";
document.getElementById("ToggleImage").src = "/_layouts/images/plus.gif";
document.getElementById("ToggleImage").alt="Show menu";
}
}
</script>

Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4128
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
We do a script that handles Javascript Cookie Get Set Delete.

However, we don't help people write their code.

Let me suggest webmasterworld.com as a place that might be a bit more interested in helping you create your code.

In general however, it's really best to learn what you need to know, ie, how do cookies work, by doing it, reading it, studying, practicing. That's the only type of code questions we support here, ie: here's my existing code, or your code, what's wrong with it.

That's fairly standard for web programming forums, but there are some that will help if a: your question is interesting to someone, or b: it's a heavily newbie focused forum. Neither instance applies this time here.

Personally, I strongly prefer server side cookie handling, with a few dynamic page exceptions, it's a lot more reliable and robust, using for example php.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours