473,791 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cookie Option

16 New Member
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 1215
acoder
16,027 Recognized Expert Moderator MVP
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
4826
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 exhausted all my other options, so I have to get this scenario working). Basically, if I POST the data normally, it works fine, except the target page has a new session ID, so I lost the session data that I *do* transfer around. However, if I...
1
1601
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() and that value to be the SELECTED value in ddlProfileNames. In other words, if there is no cookie value, then function ordering will default to ordering("Div1,Div2,Div3,Div4"). If there is a value, then that should be used in function ordering...
0
3240
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 documentation it seems it should do it anyway any advice?
2
1329
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 has chosen, so this needs to be loaded (possibly several times as they change their parameters) and I've got this working using AJAX.
4
1989
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. When the page loads I want it to check for the cookie to see if that person has voted or not. The script is creating a cookie called "vote" and setting it to 1. I've attempted to write an if statement that checks this, but I can't get it...
1
1766
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 value (for example 'miller') should be set with javascript or php. If the user chose a drop down menue on the website the cookie´s value should be overwritten with the chosen value from the drop down menu. <select name="familynames">
5
1061
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 has been delivered, so people can come to the mailboxes to pick up their incoming mail. The problem is that I want to have a staff person "set the flag" in some way. This person won't be technically savvy, nor would I want to give them...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.