2010-07-30 3 views
4

내 firefox addon에서 쿠키를 설정하는 방법은 무엇입니까?파이어 폭스 애드온에서 쿠키를 설정하는 방법은 무엇입니까?

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

이 간단한 js는 firefox addon에서는 쿠키를 설정하지 않지만 웹 페이지에서는 잘 작동합니다.

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); 

당신은 여기에서 자세한 내용을 찾을 수 있습니다 :

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

+0

왜 작동하지 않는 당신이 쿠키 관리자 XPCOM을 사용할 수있는가에 추가에서 – SLaks

답변

4

?
+0

+1 :이 코드는 정말 고마워요. :) –

+0

이 코드는 Firefox 4에서 작동하지 않는 것 같습니다. FF4/Fennec의 쿠키 서비스와 관련된 변경 사항이 있습니까? – spektom

+0

또한 플래그 HttpOnly는 해당 functionnality를 사용할 때 작동하지 않습니다. – deadalnix