简体   繁体   中英

Set HttpOnly attribute of a cookie as “True” using javascript

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM