0

I have a function in Javascript which sets a cookie like this:

document.cookie = "name='Name'" + ";EXPIRES=sometime" + ";PATH=$PATH" + ";DOMAIN=domain" + ";SECURE=''";

I want to set the HttpOnly attribute of the cookie as TRUE.

How do I do that in Javascript?

I tried the following way which didn't work out:

document.cookie.HttpOnly = true;

Also, searched in Google but did not find any solution in Javascript.

Krishnachandra Sharma
  • 1,332
  • 2
  • 20
  • 42

1 Answers1

1

As already stated, this is impossible to do. You want set a attribute that isn't avaiable for scripting languages(JavaScript is a scripting language), with javascript.

From another question:

A HttpOnly cookie means that it's not available to scripting languages like JavaScript. So there's in JavaScript absolutely no API available to get/set the HttpOnly attribute of the cookie, as that would otherwise defeat the meaning of HttpOnly.

Source: Set a cookie to HttpOnly via Javascript

If you insist on doing this with JavaScript, I'm afraid you're at a dead end.

Community
  • 1
  • 1
Billy
  • 1,104
  • 8
  • 22