仅使用HTML5设置Cookie [英] Setting a Cookie using only HTML5

查看:343
本文介绍了仅使用HTML5设置Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这篇文章中找到了其中的内容,该文章解释了如何仅使用HTML来设置Cookie

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

他使用 http-equiv 属性HTML文档的< head> 中的code>< meta> :

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

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

现在我已经阅读了有关 HTML< meta> http-equiv属性
我不明白如何使用它来设置Cookie。

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

如果您愿意,有人可以向我解释可以使用此方法设置Cookie还是那个指南只是个玩笑?
我尝试了此操作,但 HolidayGlaze 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。我还阅读了有关HTML 4.01和HTML5语法之间的差异 ,所以我的问题是有关HTML5的正确语法。

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

推荐答案

您曾经能够使用mata标签设置cookie,但是浏览器正朝着 HTTP标头,或 document.cookie

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.

如果您尝试使用meta设置cookie Chrome中的代码,您将收到警告和/或错误(取决于您的版本)。

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.


[不推荐使用]通过设置cookie。从M65开始,meta http-equiv ='Set-Cookie'...> 不再起作用。考虑切换到 document.cookie = ... ,或切换到 Set-Cookie HTTP标头。有关更多详细信息,请参见 https://www.chromestatus.com/feature/6170540112871424

[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.

 


阻止设置 Cookie示例;路径= /; expires =星期五,18年3月24日星期五10:000:00 GMT 来自< meta> 标签的cookie。

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

我可以想象其他浏览器也已弃用/删除了此功能,或者不久后将采用chrome。

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

您可以在此处了解有关此功能弃用的更多信息: https ://bugs.chromium.org/p/chromium/issues/detail?id = 767813

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

这篇关于仅使用HTML5设置Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆