inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Jul 30, 2010 3:42:06 GMT -8
Like I said, use toUTCString, as toGMTString is deprecated. toUTCString does exactly the same thing, they are the same function. toGMTString is provided for compatibility, it's recommended you use the other method instead.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Jul 30, 2010 3:45:51 GMT -8
Okay, I'll go change that now Peter - thanks
|
|
inherit
100824
0
May 13, 2012 5:37:49 GMT -8
Michael
14,585
March 2007
wrighty
|
Post by Michael on Jul 30, 2010 4:20:05 GMT -8
Like I said, use toUTCString, as toGMTString is deprecated. toUTCString does exactly the same thing, they are the same function. toGMTString is provided for compatibility, it's recommended you use the other method instead. The actual problem wasn't the "toGMTString", it was the fact that it was on the end of the .setTime() And I didn't know it was deprecated, thanks Peter.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Jul 30, 2010 8:55:59 GMT -8
var deleteCookie = function(name) { document.cookie = name + "=x; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"; }, readCookie = function(name) { var cookies = document.cookie.split(";"); name = name + "="; for (var rc = 0; rc < cookies.length; rc++) { var c = cookies[rc].replace(/^\s+/, ""); if (c.indexOf(name) == 0) return c.substring(name.length, c.length); } return null; }, setCookie = function(name, value) { var temp = new Date(); temp.setTime(temp.getTime() + 31536000000); document.cookie = name + "=" + value + "; expires=" + temp.toGMTString() + "; path=/"; };
That should work. I did some minor edits inline and haven't tested it since, but it should work. If there's a problem, it would be at the replace() in readCookie.
setCookie("test", "gummy bears"); alert(readCookie("test")); // gummy bears deleteCookie("test");
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Jul 30, 2010 8:57:09 GMT -8
Like I said, use toUTCString, as toGMTString is deprecated. toUTCString does exactly the same thing, they are the same function. toGMTString is provided for compatibility, it's recommended you use the other method instead. The actual problem wasn't the "toGMTString", it was the fact that it was on the end of the .setTime() And I didn't know it was deprecated, thanks Peter. I didn't either. Googled and it is. So OP should update that part of meh code if they use it.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Jul 30, 2010 9:05:05 GMT -8
As the code I have is working fine I'll keep it as it is right now, however I'd be interested in how that code works differently to the one I'm currently using for the cookies and if anything is 'better'
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Jul 30, 2010 11:29:54 GMT -8
The same things are happening in terms of setting and reading cookies. The one I posted just makes it easier to do, instead of having to include all the parts of document.cookie (e.g. expire and path) when setting a cookie and searching through all parts of all cookies when reading a cookie, you can just do setCookie() and readCookie(). And if you ever want to use cookies for another project in the future, it's a lot easier to just copy-paste the functions than to re-code the whole document.cookie thing.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Jul 30, 2010 21:35:14 GMT -8
Ooh okay, thanks Charles
|
|