开发者

How to set cookie under my firefox addon?

How to set cookie under my firefox addon?

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" 开发者_Go百科+ path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
setCookie("foo", "bar");

This simple js is not set cookie in firefox addon, but in web-page work well.


From the add-on you can use the cookie manager XPCOM:

    var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
    var cookieUri = ios.newURI("http://www.yourplacewhereyouwanttosetthecookie.com/", null, null);
    var cookieSvc = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);

    cookieSvc.setCookieString(cookieUri, null, "your_key=your_value;", null);

You can find more details here:

https://developer.mozilla.org/en/Code_snippets/Cookies#Setting_a_cookie

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜