0
有沒有辦法讓我在每次更改Chrome的時候設置一個cookie?我試過Chrome cookies和HTML selectBox.onchange
<select id="routeBox" name="routeBox"
onchange="getRoute(route, routeBox.selectedIndex);
chrome.cookies.set({'url':'http://127.0.0.1/', 'name':'routeCookie', 'value': this.options.selectedIndex});">
</select>
忽略getRoute,它只是再次調用xml解析器來重新填充selectBox。 Cookie部分似乎不起作用。我也嘗試創建一個名爲onchange的函數,但它也不起作用。
<select id="routeBox" name="routeBox"
onchange="getRoute(route, routeBox.selectedIndex);
setCookies('http://127.0.0.1/','routeCookie', this.options.selectedIndex);">
</select>
function setCookies(domain, name, value) {
chrome.cookies.set({'url': domain, 'name': name, 'value': value});
alert("cookie set");
}
另外:這裏是我的清單文件的片段
"permissions": [
"cookies", "tabs",
"*://*/*"
],
"content_scripts": [
{
"matches": ["http://127.0.0.1/*", "*://*/*"],
"js": ["functions.js"]
}
一如往常的任何幫助或建議將是巨大的!
爲什麼你不使用localStorage?使用起來更容易,就像聲明全局變量一樣。根據[Google的文檔](http://code.google.com/chrome/extensions/cookies.html#method-set),我不確定您可以起訴一個逗號來設置多個Cookie。我認爲你應該嘗試使用分號。 –
我實際上並未設置多個Cookie,而是將屬性設置爲Cookie。什麼是本地存儲? – infinityLoop
[Dive Into HTML5](http://diveintohtml5.org/storage.html)和[MDN's Docs](https://developer.mozilla.org/en/dom/storage#localStorage)應該可以很好地解釋它。基本上,這是一種新的存儲變量的方式,即使頁面在HTML5瀏覽器中關閉後也是如此。其中包括Chrome。 –