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:

function createCookie(name,value,days)
	var expires = "";
	if (days)
		var date = new Date();
		expires = "; expires="+date.toGMTString();
		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.

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 :slight_smile: This issue has been solved.

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)?

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.

Sounds like you have set Opera to not allow cookies.

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