Max Max - 1 year ago 97
Javascript Question

Is it safe to set cookie with unquoted path?

I would like to execute the following JavaScript to set a browser cookie:

document.cookie = "name=value;path='/'"

This works fine in Firefox, Chrome, and Safari. It does not work in IE, however. Removing the path part or unquoting
seems to set the cookie correctly in IE. I'm not an expert on the cookie spec. All of the guides online seem to quote the path. Is it required or optional to quote the path?

Answer Source

According to W3Schools correct syntax is following:

With a path parameter, you can tell the browser what path the cookie belongs to. By default, the cookie belongs to the current page.

document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download