5

Google Chrome 拡張機能を開発しています。自分のものではないドメインの Cookie を後で設定できるようにする必要があります。

これはJavaScriptでどのように可能ですか?

4

1 に答える 1

5

これは Cookie の実装例で、これで Cookie を設定できます

ここに画像の説明を入力

マニフェスト.json

{
  "name" : "Cookie API Demo",
  "version" : "1",
  "description" : "This is demonstration of Cookie API",
  "permissions": [ "cookies","<all_urls>"],
  "browser_action": {
    "default_icon": "screen.png",
    "default_popup":"popup.html"
  },
  "manifest_version": 2
}

popup.js

function cookieinfo(){
    /*chrome.cookies.getAll({},function (cookie){
        console.log(cookie.length);
        for(i=0;i<cookie.length;i++){
            console.log(JSON.stringify(cookie[i]));
        }
    });
    chrome.cookies.getAllCookieStores(function (cookiestores){
        for(i=0;i<cookiestores.length;i++){
            console.log(JSON.stringify(cookiestores[i]));
        }
    });*/
    chrome.cookies.set({"name":"Sample1","url":"http://developer.chrome.com/extensions/cookies.html","value":"Dummy Data"},function (cookie){
        console.log(JSON.stringify(cookie));
        console.log(chrome.extension.lastError);
        console.log(chrome.runtime.lastError);
    });
    /*chrome.cookies.onChanged.addListener(function (changeInfo){
        console.log(JSON.stringify(changeInfo));
    });*/
}
window.onload=cookieinfo;

popup.html

<html>
<head>
<script src="popup.js"></script>
</head>
<body>
</body>
</html>
于 2012-11-27T10:08:40.157 に答える