开发者

Running chrome.cookies.set on selectbox onchange

I'm having quite a bit of trouble with this one little thing and I was hoping someone could help me.

    <select id="routeBox" name="routeBox" 
    onchange="javascript: getRoute(route, routeBox.selectedIndex);
    setCookies('http://127.0.0.1/*', 'routeCookie', routeBox.options.selectedIndex);">
    </select>

The first function works as it is supposed to but the second function, setCookies, never runs. Here is setCookies:

    function setCookies(domain, name, value) {
    chrome.cookies.set({"url": domain, "name": name, "value": value});          
    alert("cookie set");
    }

The function is placed above the selectBox in script tags.

Any help开发者_StackOverflow社区 would be great!

Thanks


Your code appears sound and your API looks correct so I can only imagine that you possible forgot to declare the "cookies" permission in your manifest.


A couple things:

  • Unless route is a global variable, it's currently undefined in the onchange scope.
  • I would reference the routeBox object with the this keyword.
  • You don't need to add the javascript: text to the onchange attribute.

Here's your code, modified:

<select id="routeBox" name="routeBox" 
        onchange="getRoute(route, this.selectedIndex);
        setCookies('http://127.0.0.1/*', 'routeCookie', this.selectedIndex);">
</select>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜