469,313 Members | 2,621 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,313 developers. It's quick & easy.

Cookie Option

I am volunteering at a hospital and working on the intranet. They want an option to have a pop up message but they only want it to pop up once or twice, and then be able to change the content and have it re pop-up.
Example: week1 how to properly wash your hands
Week2: system wide meeting on thursday dont forget. etc etc..
I am not very good in Java. but this is what i have so far. Can anyone point me in the right direction. Greatly appreciated.
also we use active directory, so i dont know if we could maybe pull by user name? Thanks


Expand|Select|Wrap|Line Numbers
  1. var username = GetCookie('username');
  2.  
  3. if (username == null) {
  4.   username = prompt('Please enter your name (otherwise press cancel)',"WebSurfer");
  5.   if (username == null) {
  6.     alert('Its ok if you dont want to tell me your name');
  7.     username = 'WebSurfer';
  8.   } else {
  9.     pathname = location.pathname;
  10.     myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
  11.     var largeExpDate = new Date ();
  12.     largeExpDate.setTime(largeExpDate.getTime() + (365 * 24 * 3600 * 1000));
  13.     SetCookie('username',username,largeExpDate,myDomain);
  14.   }
  15. }
  16.  
  17. function getCookieVal (offset) {
  18.   var endstr = document.cookie.indexOf (";", offset);
  19.   if (endstr == -1)
  20.   endstr = document.cookie.length;
  21.   return unescape(document.cookie.substring(offset, endstr));
  22. }
  23.  
  24. function GetCookie (name) {
  25.   var arg = name + "=";
  26.   var alen = arg.length;
  27.   var clen = document.cookie.length;
  28.   var i = 0;
  29.   while (i < clen) {
  30.     var j = i + alen;
  31.     if (document.cookie.substring(i, j) == arg)
  32.     return getCookieVal (j);
  33.     i = document.cookie.indexOf(" ", i) + 1;
  34.     if (i == 0)
  35.     break;
  36.   }
  37.   return null;
  38. }
  39.  
  40. function SetCookie (name, value) {
  41.   var argv = SetCookie.arguments;
  42.   var argc = SetCookie.arguments.length;
  43.   var expires = (argc > 2) ? argv[2] : null;
  44.   var path = (argc > 3) ? argv[3] : null;
  45.   var domain = (argc > 4) ? argv[4] : null;
  46.   var secure = (argc > 5) ? argv[5] : false;
  47.   document.cookie = name + "=" + escape (value) +
  48.     ((expires == null) ? "" : ("; expires=" +
  49.     expires.toGMTString())) +
  50.     ((path == null) ? "" : ("; path=" + path)) +
  51.     ((domain == null) ? "" : ("; domain=" + domain)) +
  52.     ((secure == true) ? "; secure" : "");
  53. }
Mar 20 '08 #1
1 1075
acoder
16,027 Expert Mod 8TB
Cookies would only work for one particular computer/browser. If you need this over a number of computers/users, use server-side code.
Sep 6 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Keith Patrick | last post: by
1 post views Thread by evanburen | last post: by
reply views Thread by joseph conrad | last post: by
2 posts views Thread by Griff | last post: by
1 post views Thread by marc heiners | last post: by
5 posts views Thread by Mike Copeland | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.