Setting a Cookie using only HTML5

怎甘沉沦 提交于 2019-12-31 07:04:46

问题


I found this article where it explains how to set a cookie using only HTML.

He use http-equiv attribute on the <meta> in the <head> of an HTML document:

<meta http-equiv="set-cookie" content="___________">

Now I have read about HTML < meta> http-equiv Attribute but I could not understand how to use it for set a cookie.

Someone can explain to me if you can use this method for set cookie or that guide is just a joke? I tried this but HolidayGlaze cookie has not been saved.

<meta http-equiv="set-cookie" content="HolidayGlaze=Good%20yummies; expires=Sat, 25-Nov-2023 12:00:00 GMT; domain=.example.com; path=/; secure; httponly;">

P.S. I read also about Differences Between HTML 4.01 and HTML5 syntax so my question is about the correct syntax for HTML5.


回答1:


You used to be able to set cookies using a mata tag, however browsers are moving away from that in favour of HTTP headers, or document.cookie.

If you try to set a cookie using meta tags in Chrome, you will get a warning and/or error (Depending on your version). The feature has been deprecated in M63, and completly removed in M65.

[Deprecation] Setting cookies via <meta http-equiv='Set-Cookie' ...> no longer works, as of M65. Consider switching to document.cookie = ..., or to Set-Cookie HTTP headers instead. See https://www.chromestatus.com/feature/6170540112871424 for more details.

 

Blocked setting the Example cookie; path=/; expires=Friday, 24-Mar-18 10:00:00 GMT cookie from a <meta> tag.

I would imagine that other browsers also have this feature deprecated/removed, or will follow suit shortly with chrome.

You can read more about the deprecation of this feature here: https://bugs.chromium.org/p/chromium/issues/detail?id=767813




回答2:


Don't set cookies in HTML with meta http-equiv="set-cookie". It's outdated and has no effect in modern browsers that follow the current HTML5 standard (it's non-conforming in HTML5).



来源:https://stackoverflow.com/questions/49450549/setting-a-cookie-using-only-html5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!