I am running Android Honeycomb 3.2.1 and I am having trouble getting the browser to stop accepting cookies. I have the following code:
first.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="cookie.js"></script>
<script type="text/javascript">
setCookie('testing','test cookie',365);
window.location.href = 'second.html';
</script>
</head>
<body>
</body>
</html>
second.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="cookie.js"></script>
<script type="text/javascript">
var temp = getCookie('testing');
alert(temp);
</script>
</head>
<body>
</body>
</html>
cookie.js:
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
return null;
}
Now if I shut off cookies and visit first.html on any of my desktop browsers, I get redirected and get an alert that says null as expected.
If I turn on my cookies and visit first.html on any of my desktop browsers, I get redirected and get an alert that says “test cookie” as expected.
Now if I run this on my Android tablet with cookies disabled it always returns “test cookie” in an alert. It doesn’t matter if I have cookies on or off. I have tried changing the settings, removing the cookies and cache, restarting the browser and even restarted the tablet and all with the same results.
Any help is appreciated.
I am having the same problem – we ended up checking cookies on the server and returning an HTTP error code if cookies were not set.