SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Non-Member
    Join Date
    Oct 2007
    Location
    United Kingdom
    Posts
    623
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question Why doesn't "document.cookie = 'thecookie=; expires=; path=/;';" make a cookie in IE?

    I don't understand why

    Code JavaScript:
    document.cookie = 'thecookie=; expires=; path=/;';
    sets an empty cookie (called "thecookie" that expires when the browser closes and is accessible via any directory on the website)
    in all the browsers I have tried apart from IE7?

    Thanks

    ro0bear

  2. #2
    Non-Member
    Join Date
    Aug 2006
    Location
    Kansas City
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shot in the dark:

    I don't know how many cookies you are using but, IE7 only allows 20 cookies per domain..


    Don't forget to put in empty quotes for the unused parameters or you'll get an error when you run the code.


    Hope it helps.

  3. #3
    Non-Member
    Join Date
    Oct 2007
    Location
    United Kingdom
    Posts
    623
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks, this seems to work perfectly in all browsers...

    Code JavaScript:
    document.cookie = 'thecookie=""; path=/';

    Now to fix the other IE bugs, agh! You would have thought Microsoft deliberately made it difficult for developers!

    Thanks for your help

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    This should help you then. Some proper cookie handling functions from http://www.quirksmode.org/js/cookies.html

    Code javascript:
    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);
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    Non-Member
    Join Date
    Oct 2007
    Location
    United Kingdom
    Posts
    623
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks Paul, the other IE problems are not problems with the cookies though unfortunately.

    Much appreciated all the same though, thanks

    I will see if I can work out what’s wrong with it tomorrow.

    I think in future when I write a program in JavaScript I will check both in Firefox and IE as I go, so I can fix problems as the occur rather than searching through looking for what’s wrong lol. (also writing functions to make solving cross browser problems in the future nice and easily).

    Thanks again

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    You'll find that it's a lot easier to develop on something like Firefox and apply fixes for IE, than to do it the other way around where you develop for IE and apply fixes for Firefox.

    It need not be Firefox of course, there's also Google Chrome, Safari, Opera which are popular ones.

    The issue is that there is a [http://en.wikipedia.org/wiki/Comparison_of_web_browsers vast number of web browsers] out there, so it's best to develop from a common set of standards and then apply cross-browser techniques where required.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •