I need help how to use correctly the javascript : “document.cookie” or
how to write cookie from javascript in Android web browser ?
I’ve make sure in the settings that cookie is enabled. When I checked
by using “navigator.cookieEnabled”, it returns true as well.
I’ve a piece of javascript code as follow that has been working
everywhere
( e.g. PC browsers, iPhone ), but doesn’t work in Android.
function createCookie(name) {
// cookies expired in 1 year.
var expDate = new Date();
expDate.setDate(expDate.getDate() + 365);
expDate = expDate.toGMTString();
var el = document.getElementById(name);
document.cookie = name + '=' + escape(el.value) + '; path=/ ;expires=' + expDate;
document.cookie = name + '-idx=' + escape(el.selectedIndex) + ';path=/ ; expires=' + expDate;
//alert('cookie : ' + document.cookie);
}
When I open the ‘alert‘ comment in the last line of code, Android will
just show blank while
all other browsers show me the content of the cookie that I’ve just
written.
Please help.
Thanks.
Ok, now I really got it (window.cookie, lol).
Just remove the space in the
pathdefinition. Seemed to work on my phone.Edit: Put all the strings on one line too, I think it screwed up the parsing.