FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Javascript, Display Cookie.

 


Dougie1
What would I have to do in javascript to make it so that I could output the content of the cookie (so that it can be read by the user) JSESSIONID? Thanks.
jabapyth
Heres some javascript code
Code:
function createCookie(name,value,days) {
   if (days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
   }
   else var expires = "";
   document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}

function eraseCookie(name) {
   createCookie(name,"",-1);
}


courtesy of Quirksmode.org
minik
You can find information about Javascript cookies at http://www.w3schools.com/js/js_cookies.asp. It basically explains about the whole concept of cookies and how to store them. You can find information about PHP cookies aswell at http://www.w3schools.com/php/php_cookies.asp. That shows information about cookies again and how they work and how to store and display information.
Dougie1
Yes but how would I display the content. I don't really know how javascript functions work. I have found all these sites but because I am basically jumping straight to this I don't understand how everything works. I do not have the time or need to learn javascript and only need it for this.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.