473,387 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1195
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

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

Similar topics

2
by: Keith Patrick | last post by:
I'm trying to programmatically post data to another page within my ASP.Net app. Not POSTing is not an option (I can't store this data in my session, context, hidden fields, or anything else...I've...
1
by: evanburen | last post by:
When my page loads, I check for the existence of a cookie value through readCookie(). If there is a value present for the cookie, I would like that to be the default value in function ordering()...
0
by: joseph conrad | last post by:
Hi, I tried to implement my own session handler in order to keep control on the process the drawback I foun it is not creating and storing in my cookie the PHPSESSID variable anymore. reading te...
2
by: Griff | last post by:
Hi I have an HTML search page that contains a drop-down box with approximately 78,000 items in it. The actual content of this select box varies depending upon some of the parameters a user...
4
toxicpaint
by: toxicpaint | last post by:
Hi there, I've built a form for peolpe to submit a vote and I thought the best way to restrict people voting twice would be to create a cookie called "voted" and set the value to 1 when they vote....
1
by: marc heiners | last post by:
Hello! I have to overgive an information from one website to another (same domain) by sertting a cookie with javascript. When the website is requested by a user a session cookie with a default...
5
by: Mike Copeland | last post by:
In a Web site I'm building, I want to provide an ability to set a "flag" message that users can see when they log on. Specifically, I want the "flag" to show when the (snail) mail for our building...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.