Go Back   PCMech Forums > Help & Discussion > Internet, Web Applications, & The Cloud

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-14-2008, 12:39 PM   #1
Member (7 bit)
 
Join Date: Oct 2007
Location: Ohio
Posts: 101
Send a message via AIM to Silvers24 Send a message via Yahoo to Silvers24
Java Cookie Help!

ok, i found the coding I need, but I have no damn clue how to edit it! Or what to edit more put.
First up the Java Script. I know how to save it, but I need to know what to edit.
Code:
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

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();
}

var favorite = GetCookie('animal');

if (favorite != null) {
switch (favorite) {
case 'cat' : 	url = 'cat.html'; // change these!
	     	break;
case 'dog' : 	url = 'dog.html';
	     	break;
case 'gerbil' : url = 'gerbil.html';
		break;
case 'gopher' : url = 'gopher.html';
		break;
}
// window.location.href = url;
alert('You would have been taken to the ' + favorite + ' page (' + url + '), but this is just a demo!');
}
Second is how to get the links to work, I want to use the
Code:
a href="'
link, but I dunno how to make it so it works with the javascript.
I do have this
Code:
onClick="SetCookie();">
but where to put it? how to edit and use it?
Silvers24 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java for XP Pro. SP2 ( should I insatll ) Charlie W Windows Legacy Support (XP and earlier) 9 02-27-2007 11:44 PM
Computer Acronyms Floppyman Computer Hardware 156 06-18-2006 06:25 AM
How do I stealth ports? jsun Networking & Online Security 9 08-21-2005 03:59 PM
Java script works but java applets won't lexi Windows Legacy Support (XP and earlier) 13 09-14-2003 07:11 AM
Microsoft Wins Stay on Order to Add Java morriswindgate General Discussion 7 02-05-2003 09:34 AM


All times are GMT -5. The time now is 07:05 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2