[英]Set chrome extension cookie value name as var
I'm working on chrome extension and need to set a cookie: 我正在开发chrome扩展程序,需要设置一个cookie:
chrome.cookies.set({ url: "https://www.someurl.com/", name: value });
This code works good but "name" should be dynamic var that ajax passed. 这段代码运行良好,但是“名称”应该是ajax传递的动态var。
var name = response;
Is it posible? 有可能吗?
You're using it wrong . 您使用错了 。
It should be: 它应该是:
chrome.cookies.set({
url: "https://www.someurl.com/",
name: someName,
value: someValue
});
So you can set both as variables. 因此,您可以将它们都设置为变量。
However, in a general case (say, chrome.storage
API that really takes name-value maps), you could do the following: 但是,在一般情况下(例如,实际上使用名称-值映射的chrome.storage
API),您可以执行以下操作:
var data = {};
data[name] = value; // Both are variables
chrome.storage.local.set(data);
When ECMAScript 6 support comes along, you'll be able to use Computed property names : 当ECMAScript 6支持出现时,您将能够使用Compute属性名称 :
// Does not work yet
chrome.storage.local.set({[name]: value});
We won't have to wait long though, it's coming in Chrome 44 . 不过,我们无需等待很长时间, 它已经安装在Chrome 44中 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.