Here is my code for setting a cookie:
function setCookie(c_name, value, expiredays)
{
alert("setting cookie!");
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = c_name + "=" + escape(value) +
((expiredays === null) ? "" : ";expires=" + exdate.toUTCString());
}
I’m using Phonegap to make an app on Android phones, which should just use and set cookies like a regular browser. It doesn’t seem to be setting the cookie, though, and because of the environment (on my pnone), I can’t debug.
So, is there a way I can make an alert to tell me if document.cookie fails, and ideally any error message that might tell me why?
I tried just doing alert(document.cookie), but it’s not outputting anything, so I’m hoping there’s another way to trap the output.
You can use try/catch statement: