CACuzcatlan
CACuzcatlan

Reputation: 5497

Is it possible to set a page specific cookie?

I know it is possible to set a cookie for a path such as "/" or "/folder/", but is it possible to set a cookie for a specific page, such as "/folder/page.html"?

Upvotes: 5

Views: 3515

Answers (2)

Matt
Matt

Reputation: 911

I just insert the page name into the cookie and retrieve based on that name.

var parts = window.location.pathname.split('/');
var pageName = parts[parts.length -1];
var baseNmae = 'somebase';
var cookieName = baseName + '_' + pageName;

then save/read cookie with cookieName name.

(make sure your path is set for the cookie too)

Upvotes: 1

jro
jro

Reputation: 7480

No.

More specifically, browsers don't care about page specifics -- only paths. Browsers submit cookies on page requests based on the path of the url; the specific resource at that location is irrelevant.

On the flip side, why would you want to limit a cookie based on a specific page?

Upvotes: 4

Related Questions