@konithomimoSep 16.2008 — #Sorry, read your post wrong (split instead of substring). most likely it was meant ot be split(','). substring(,) should do nothing, or in some browsers throw and error, because both arguments will be null.
@vortexerauthorSep 16.2008 — #Thank you, is there an easy way to get it to show the first value of the cookie only, the cookie name? Or is there another easy way to do that.
@rnd_meSep 17.2008 — #Thank you, is there an easy way to get it to show the first value of the cookie only, the cookie name? Or is there another easy way to do that.
Thanks you very much for your help.[/QUOTE] [CODE] var firstCookieName = document.cookie.toString().split(/;/g)[0].split("=")[0]; alert(firstCookieName); [/CODE]
@vortexerauthorSep 17.2008 — #Thanks I have done lots of googles for it already, only shows long functions. Came here to try to find something shorter.
var firstCookieName = document.cookie.toString().split(/;/g)[0].split("=")[0];
alert(firstCookieName);[/QUOTE]
This is working well but its only returning one cookie name. Would if a page has a few cookie names already on it. How can I get it to show any cookie names for a page. The first cookie that is in the cookie variable of
@rnd_meSep 17.2008 — #[CODE] //compatibility code: if (!Array.prototype.map) {// from http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:map Array.prototype.map = function (fun) {var len = this.length;if (typeof fun != "function") {throw new TypeError;}var res = new Array(len);var thisp = arguments[1];for (var i = 0; i < len; i++) {if (i in this) {res[i] = fun.call(thisp, this[i], i, this);}}return res;};}
//returns array of all cookie names: document.cookie.toString().split(/;/g).map(function(a){return a.split("=")[0];})
Array.prototype.map = function (fun) {var len = this.length;if (typeof fun != "function") {throw new TypeError;}var res = new Array(len);var thisp = arguments[1];for (var i = 0; i < len; i++) {if (i in this) {res[i] = fun.call(thisp, this[i], i, this);}}return res;};}
Not working, anyone know of a real easy way to read cookie names without a real long function? Please let me know thank you very much for your help.[/QUOTE]
i just re-tested in FF3, IE7. might want to take another look.
@vortexerauthorSep 18.2008 — #Thanks some reason not working for me in any browser but no error messages either. Have the script above the last </head> tag in a regular .html page. Even set the cookie name vv first. Still nothing. <script type="text/javascript">
function setCookie(name, value, days)
{var expires = "", date = new Date(); if (days)
{expires = ";expires=" + new Date(date.setDate(date.getDate() + days)).toGMTString();}
document.cookie = name + "=" + value + expires + "; path=/"; } setCookie('vv', 'vvv', 365);
if (!Array.prototype.map) {
Array.prototype.map = function (fun) {var len = this.length;if (typeof fun != "function") {throw new TypeError;}var res = new Array(len);var thisp = arguments[1];for (var i = 0; i < len; i++) {if (i in this) {res[i] = fun.call(thisp, this[i], i, this);}}return res;};}
@rnd_meSep 18.2008 — #Thanks some reason not working for me in any browser but no error messages either. Have the script above the last </head> tag in a regular .html page. Even set the cookie name vv first. Still nothing.[/QUOTE]
your date is being set to either the current time or an invalid date, and thus; expires immediately.
months only go up to 31 days.
the way your script is coded, you try to set the day of month to 383 (for sep 18th).
@vortexerauthorSep 19.2008 — #Thanks, setCookie function sets expire for days. 365 in the last field means won't expire until a year from now so should work.
@rnd_meSep 19.2008 — #Thanks, setCookie function sets expire for days. 365 in the last field means won't expire until a year from now so should work.[/QUOTE]
yes, it [U]should [/U]set the expiry a year from now, it [U]doesn[/U]'t.
from your setCookie: [CODE]expires = ";expires=" + new Date(date.[B][U][COLOR="Red"]setDate[/COLOR][/U][/B](date.getDate() + [B][U][COLOR="Red"]days[/COLOR][/U][/B])).toGMTString()[/CODE]
check out the docs on setDate for a second opinion.