如何修改子域中的现有Cookie? [英] How to edit existing cookies in subdomains?

查看:91
本文介绍了如何修改子域中的现有Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果lol.com的子域名有一个名为a的值为a的Cookie,并且域名为.lol.com,如果您打开了控制台,您将如何从lol.com编辑该Cookie (使用Chrome控制台检查chrome元素)。
也可以编辑它,如果cookie的域名是a.lol.com?他们都是https://

If a subdomain of lol.com has a cookie named "a" with value "a" and that has a domain of .lol.com how would you edit that cookie from lol.com if you have a console open in it (using JS console from inspect element in chrome). Also would it be possible to edit it too if the cookie's domain was a.lol.com? They are both https://

谢谢。

推荐答案

在添加新的Cookie之前,您必须将其分配到特定域。

Before adding a new cookie you must assign it to specific domain.

示例:

此功能可帮助您轻松添加Cookie:

This function helps you to easily add cookies:

function setCookie(cName, cValue, cExpireInDays, cDomain){
    var d = new Date();
    d.setTime(d.getTime() + (cExpireInDays*24*60*60*1000));
    var expires = "expires="+ d.toUTCString();
    document.cookie = cName + "=" + cValue + "; " + expires + ";domain="+cDomain+";";
}

sub.lol.com 打开控制台并通过调用 setCookie 功能添加新的Cookie

From sub.lol.com open console and add new cookie by calling the setCookie function

setCookie("Test", "TestValue", 4, "lol.com");

前往 lol.com 时间控制台,并写 document.cookie ,您将得到以下数据:

Go to lol.com open another time the console, and write document.cookie you will get the following data:

"Test=TestValue; OTHER_COOKIES..."

如果要编辑它,与 之前的域名相同的新Cookie只需调用 setCookie 函数。

If you want edit it you must add a new cookie with the same domain as we did before or just call the setCookie function.

这篇关于如何修改子域中的现有Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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