Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old March 20th, 2008, 06:02 PM
Newbie
 
Join Date: Jan 2008
Location: Michigan
Age: 19
Posts: 15
Default 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. }

Last edited by Nepomuk; September 5th, 2008 at 11:30 AM. Reason: Added [code] tags
Reply
  #2  
Old September 6th, 2008, 01:10 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,964
Default

Cookies would only work for one particular computer/browser. If you need this over a number of computers/users, use server-side code.
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.