Setting/Retrieving Cookies

This is a discussion on "Setting/Retrieving Cookies" within the Web Page Design section. This forum, and the thread "Setting/Retrieving Cookies are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 10th, 2006, 17:53
Junior Member
Join Date: Jan 2006
Location: West Wycombe
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Setting/Retrieving Cookies

I apologise if this is in the wrong Forum but I'm unsure into which category "cookies" fall.

I would like visitors to nominate the style of the site when they visit.

I don't need them to log-in, just select a "style" on their first visit and place a cookie accordingly, but I don't have a clue how setup such a procedure.

Can anyone help or point me in the right direction?

Thank you
Reply With Quote

  #2 (permalink)  
Old Jan 10th, 2006, 20:16
Junior Member
Join Date: Jan 2006
Location: Leeuwarden, NL
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Post Re: Setting/Retrieving Cookies

Hmm difficult. I will give you a script: User can choose background, cookie will be set and remembers background. Hope you'll like this.


HTML: Select all
<!-- TWO STEPS TO INSTALL COOKIE - FAVORITE BACKGROUND COLOR:

   1.  Paste the designated coding into the HEAD of your HTML document 
   2.  Put the last script into the BODY of your HTML document  -->

<!-- STEP ONE: Copy this code into the HEAD of your HTML document  -->
		  
<HEAD>

<SCRIPT LANGUAGE = "JavaScript">
<!-- Original:  Mattias Sjoberg -->

<!-- Begin
var expDays = 30;
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);
}
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();
}
// End -->
</SCRIPT>

<!-- STEP TWO: Copy this code into the BODY of your HTML document  -->

<BODY>

<SCRIPT>
document.write('your favorite background color is : ' + color());
</SCRIPT><br>
<a href="javascript:set()">Change background color</a>
</textarea><br></td></tr>
</table>
</form>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
Reply With Quote
  #3 (permalink)  
Old Jan 10th, 2006, 20:34
Junior Member
Join Date: Jan 2006
Location: West Wycombe
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Re: Setting/Retrieving Cookies

AnneJan

Thank you very much indeed, I shall give it a try, I'm sure it will work fine.

Again, many thankx

Mike
Reply With Quote
Reply

Tags
settingretrieving, cookies

Thread Tools

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with my Servlet - retrieving images from database Love2Java Other Programming Languages 2 May 27th, 2008 17:15
example of Inserting and Retrieving data from xml file hanusoft Classic ASP 1 Sep 25th, 2007 17:21
retrieving and displaying line breaks nate2099 Databases 1 Jul 13th, 2007 08:56
Retrieving text from database and writing back as url wheatus Classic ASP 5 Dec 22nd, 2004 11:36
Storing and Retrieving Multiple Objects From 1 ... courtjester Classic ASP 9 Sep 12th, 2004 16:37


All times are GMT. The time now is 10:39.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43