Results 1 to 3 of 3

Thread: Permanent and Session-Only Cookies

  1. #1
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default Permanent and Session-Only Cookies

    Hi,

    Can anyone change this script to pernament cookies?

    Code:
    	function cookieSave(name, text) {
    		document.cookie = name + "=" + escape(text);
    	}
    
    	function cookieLoad(name) {
    		var search = name + "=";
    		if (document.cookie.length > 0) {
    			offset = document.cookie.indexOf(search);
    			if (offset != -1) {
    				offset += search.length;
    				end = document.cookie.indexOf(";", offset);
    				if (end == -1) {
    					end = document.cookie.length;
    				}
    				return unescape(document.cookie.substring(offset, end));
    			}
    		}
    	}
    Somewhere in my mind is the solution to this problem... but I can't think of it right now

    Thanks
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There are no truly permanent javascript cookies. Cookies can be refused or cleared by the user. The user could use a different browser or computer on subsequent visits. You can set a cookie with a long, long expiration and, as long as it is accepted by the browser and not cleared by the user, it will persist until its expiration for that browser on that computer. If you want something more permanent or user specific, use server side cookies or database with user login. The cookie unit at quirksmode.org is decent and allows for setting optional expiration:

    http://www.quirksmode.org/js/cookies.html

    The actual code for the cookie unit is about half way down the rather long page at the above link.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Thanks

    And I only want to create a fake "auto-save" in case people press the Refresh button or the Restart button or close their browser or whatever. (OR get a BSoD)
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •