SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Location
    Taiwan
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie problem on Safari

    Please try the following code. It works fine on Firefox, IE, and Opera. But not on Safari.

    On Safari, the cookie can be created but cannot be cleared.

    HTML Code:
    <html>
    <head>
    	<script type="text/javascript">
    
    		function createCookie() {
    			document.cookie = "myCookie = 1; expires = Thu, 02 Jan 2031 00:00:01 UTC;";
    		}
    
    		function clearCookie() {
    			document.cookie = "myCookie =; expires = " + new Date().toUTCString();
    		}
    
    		function checkCookie() {
    			if(document.cookie.match("myCookie")) alert("Yes");
    			else alert("No");
    		}
    
    	</script>
    </head>
    <body>
    
    	<div>
    		<a href="javascript:createCookie()">create</a>
    		<a href="javascript:clearCookie()">clear</a>
    		<a href="javascript:checkCookie()">check</a>
    	</div>
    
    </body>
    </html>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    This I presume is when running the code locally, and not on a server?

    Google Chrome doesn't support local cookies, unless you start the browser with --enable-file-cookies
    See http://code.google.com/p/chromium/issues/detail?id=535
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Location
    Taiwan
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    This I presume is when running the code locally, and not on a server?

    Google Chrome doesn't support local cookies, unless you start the browser with --enable-file-cookies
    See http://code.google.com/p/chromium/issues/detail?id=535
    Ya, I had just noticed this Google Chrome problem. Thank you.


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
  •