SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot blackman890's Avatar
    Join Date
    Feb 2005
    Location
    Iceland
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Opera not saving cookies

    Hi there. On my website I have a simple shop where you can add items to your cart. To make things nicer, we have Javascript to handle the process to make it faster. The problem I am having is that Opera does not save the cookie that the javascript creates.

    Here's the relevant code:

    Code:
    function createCookie(name,value,days)
    {
    	var expires = "";
    	if (days)
    	{
    		var date = new Date();
    		date.setTime(date.getTime()+(days*24*60*60*1000));
    		expires = "; expires="+date.toGMTString();
    	}
    	else
    		expires = "";
    
    	document.cookie = name+"="+value+expires+"; path=/";
    }
    Full code: http://kisildalur.is/web/scripts/cart.js

    You can see it live if you go to http://kisildalur.is/?p=1&id=7 click on "Kaupa" (Icelandic for Buy) on any item. You will see a nice simple animation once you do. Once an item has been added, a cookie is created but in my Opera 10.53 the cookie does not exist. Browsing any other pages will result in the cart being empty.

    What am I doing wrong? :S Works for every other major browser except Opera.
    Jonatan Nilsson
    Iceland
    C# Programmer - XML & DirectX (y = hx + c)

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Sounds like you have set Opera to not allow cookies.

    Go to Tools/Preferences/Advanced and check what options you have set for Cookies.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Zealot blackman890's Avatar
    Join Date
    Feb 2005
    Location
    Iceland
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Set to Accept Cookies. Still doesn't work. Is it working in your opera browser? I tested it on other computers with Opera and it has the same problems. If I disable the javascript, the cookie get's saved. But for some reason, when javascript tries to create the cookie Opera does nothing.
    Jonatan Nilsson
    Iceland
    C# Programmer - XML & DirectX (y = hx + c)

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you get an error message in the error console?

    Have you tried using Dragonfly to debug the JavaScript? Set a breakpoint at the start of the function and single-step through it, inspecting variables along the way to see what happens.

    One thing that has tripped me up when dealing with cookies has been when the value contains non-ASCII characters. Maybe you can try to use escape(value) or encodeURIComponent(value)?
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Zealot blackman890's Avatar
    Join Date
    Feb 2005
    Location
    Iceland
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I could have sworn I had tested it too but it turns out you were right, I had to run it though escape() in order for it to work on Opera.

    Thanks for all the help This issue has been solved.
    Jonatan Nilsson
    Iceland
    C# Programmer - XML & DirectX (y = hx + c)


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
  •