Help! How to create a cookie by javascript???

Author Message
milkcat

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 10/2/2001
  • Location:
  • Status: offline
Help! How to create a cookie by javascript??? Wednesday, October 03, 2001 8:06 AM (permalink)
0
Original message moved by TNO
Reason :
Hi.. i am trying to create a cookie for the username..so everytime the user go into the site from same browser no need to type in their username, only the password.

 
#1
    imav8n

    • Total Posts : 95
    • Scores: 0
    • Reward points : 0
    • Joined: 7/3/2001
    • Location: USA
    • Status: offline
    Re: Help! How to create a cookie by javascript??? Wednesday, October 03, 2001 4:01 PM (permalink)
    0
    Rather than cutting/pasting the code...here is a link to find what you are looking for:

        http://javascript.internet.com/cookies/name.html

    The site http://javascript.internet.com has many examples of code which are avaialable to cut/paste to perform a variety of functions.

    Good Luck!

    ~imav8n
     
    #2
      TNO

      • Total Posts : 2094
      • Scores: 36
      • Reward points : 0
      • Joined: 12/18/2004
      • Location: Earth
      • Status: offline
      RE: Re: Help! How to create a cookie by javascript??? Wednesday, March 19, 2008 11:11 AM (permalink)
      0
      Put this in a separate library, or at the top of your page. Here is the API:

      Cookie.getCookie(name)
      Cookie.deleteCookie(name,path,domain)
      Cookie.setCookie(ame,value,expires,path,domain,secure)


       var Cookie = (function (){
       	return {
       		getCookie : function(name){
       			var start = document.cookie.indexOf(name + "=");
       			var len = start + name.length + 1;
       			if ((!start) && (name !== document.cookie.substring(0, name.length))){
       				return null;
       			}
       			if (start === -1) {
       				return null;
       			}
       			var end = document.cookie.indexOf(';', len);
       			if (end === -1) {
       				end = document.cookie.length;
       			}
       			return unescape(document.cookie.substring(len, end));
       		},
       		deleteCookie : function (name,path,domain) {
       			if (Cookie.getCookie(name)) {
       				document.cookie = name + '=' + ((path) ? ';path=' + path : '') + ((domain) ? ';domain=' + domain : '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
       			}
       		},
       		setCookie : function(name,value,expires,path,domain,secure){
       			var today = new Date();
       		
       			if(expires){
       				expires = expires*1000*60*60*24;
       			}
       		
       			var expires_date = new Date(today.getTime() + (expires));
       		
       			name = name;
       			value = escape(value);
       			expires = ((expires) ? ";expires=" + expires_date.toGMTString() : "");
       			path = ((path) ? ";path=" + path : "");
       			domain = ((domain) ? ";domain=" + domain : "");
       			secure = ((secure) ? ";secure" : "");
       			today.setTime(today.getTime());
       		
       			document.cookie = name + "=" + value + expires + path + domain + secure;
       		}
       	}
       })();
       
      To iterate is human, to recurse divine. -- L. Peter Deutsch
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9