|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi all,
I am using a piece of Javascript code to toggle the viewing of divisions of my website, so a division can be "opened" and "closed" at user disgresion. You can see a live example of what I mean here: www.crewdy.co.uk/layout.html The problem that I have is that when the page is refreshed or a link is clicked, the page reloads and the divisions are re-opened. I am looking for a piece of code which will enable a cookie, telling the browser to keep that division open until the user next clicks the "open/close" link. If anybody knows of where I can find a piece of code, or if anybody could help to write a piece of code to go with this, I would be greatly appreciative. May be safe to note that my JavaScript knowledge is zero-to-none; the code I am currently using is below. Thanks, Pete Code:
<!--
function toggleLayer(whichLayer)
{
if (document.getElementById)
{
var style2 = document.getElementById(whichLayer).style;
style2.display = style2.display? "":"none";
}
}
-->
|
|
|||
|
Here's something I've used to save a user's background color preference:
<script language="JavaScript"> var expDays = 90; var exp = new Date(); exp.setTime(exp.getTime() + (expDays*24*60*60*1000)); function color(){ var favColor = GetCookie('color'); if (favColor == null) { favColor = prompt("What is your favorite background color?"); SetCookie('color', favColor, exp); } document.bgColor=favColor; return favColor; } function set(){ favColor = prompt("What is your favorite background color?"); SetCookie ('color', favColor, exp); document.location="fgd.htm" } function getCookieVal (offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); } function 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 getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } function SetCookie (name, value) { var argv = SetCookie.arguments; var argc = SetCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; var path = (argc > 3) ? argv[3] : null; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : ""); } function DeleteCookie (name) { var exp = new Date(); exp.setTime (exp.getTime() - 1); var cval = GetCookie (name); document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); } </script> |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |