1

I have disabled cookies in IE and would like to check with the help of jquery whether cookies are enabled in browser or not. I have written some functionality to check but it is not working in IE browser.

After disabling the cookie in IE. I am trying to set cookie in IE broswer. It is still setting even though I disabled the cookie in the settings.

Thanks in advance

Code:

 $.cookie = function (name, value, options) {
 if (typeof value != 'undefined') { // name and value given, set cookie
   options = options ||{};
 if (value === null) {
  value = '';
  options.expires = -1;
 }
  var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  var date;
if (typeof options.expires == 'number') {
 date = new Date();
 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
 } else {
   date = options.expires;
}
   expires = '; expires=' + date.toUTCString(); }                 
var path = options.path ? '; path=' + (options.path) : '';
 var domain = options.domain ? '; domain=' + (options.domain) : '';
  var secure = options.secure ? '; secure' : '';
  document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
 } else { // only name given, get cookie
 var cookieValue = null;
 if (document.cookie && document.cookie != '') {
 var cookies = document.cookie.split(';');
 for (var i = 0; i < cookies.length; i++) {
 var cookie = $.trim(cookies[i]);

 if (cookie.substring(0, name.length + 1) == (name + '=')) {
  cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
 break;
 }}
 }
 return cookieValue;
 }
  };
 $.cookie("locations", 1);
 if ($.cookie('locations') == null) {
 //cookie does not exist, just set cookie to empty
  alert('cookie empty');       
 }
VSri58
  • 3,691
  • 2
  • 14
  • 16
user3661407
  • 525
  • 3
  • 9
  • 18

0 Answers0