Disabling cookies in Android browser does not work

I am running Android Honeycomb 3.2.1 and I am unable to force 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 turn off cookies and run first.html in any of my desktop browsers, I get redirected and get a warning that says null as expected.

If I turn on my cookies and run first.html in any of my desktop browsers, I get redirected and get a warning that says “test cookie”, as expected.

Now, if I run this on my Android tablet with cookies disabled, it always returns a “test cookie” in the warning. It doesn't matter if I have cookies. I tried to change the settings, delete cookies and cache, restart the browser and even restart the tablet and all with the same results.

Any help is appreciated.

+6
source share
1 answer

How to check if cookies are allowed before returning a cookie:

 function getCookie(c_name) { if(navigator.cookieEnabled) { 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; } 
0
source

Source: https://habr.com/ru/post/903771/


All Articles