faqts : Computers : Programming : Languages : JavaScript : Browser Settings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 14 people (64%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How to detect if cookies are enabled in Netscape navigator 4.x

Feb 13th, 2003 12:56
Sanoj Shivashankaran, Sanoj S,


<script language="javascript">

window.onload = funLoad;

function funLoad(){
    setcookie("testCookie","cookieValue", 2);
    var strCookieVal = getcookie("testCookie");
		
   if(strCookieVal != "cookieValue"){					
       alert("Cookies disabled");
   }
   else{			
     alert("Cookies enabled");
   }
}

function getcookie(cookiename) {
   var cookiestring=""+document.cookie;
   var index1=cookiestring.indexOf(cookiename);
   if (index1==-1 || cookiename=="") return ""; 
   var index2=cookiestring.indexOf(';',index1);
   if (index2==-1) index2=cookiestring.length; 	 	 
   return unescape
(cookiestring.substringindex1+cookiename.length+1,index2)); 
    
}

function getexpirydate(nodays){
    var UTCstring;
    var Today = new Date();
    var nomilli=Date.parse(Today);
    Today.setTime(nomilli+nodays*24*60*60*1000);
    var UTCstring = Today.toUTCString();	
    return UTCstring;
}

function setcookie(name,value,duration){
  cookiestring = name + "=" + escape(value) + ";EXPIRES=" + 
getexpirydate(duration);
  
  document.cookie=cookiestring;
}


</script>