views:

113

answers:

1

I'm working on a Google Chrome Extension and would like to get an HTML from within my popup HTML to call functions within my loaded javascript file. My manifest follows:

{
    "name": "Extension",
    "version": "1.0",
    "description": "Extension",
    "browser_action": {
        "default_icon": "icon.png",
        "default_title": "Ext",
        "popup": "popup.html"
    },
    "content_scripts": [{
        "matches": ["http://*/*"],
        "css": ["ext.css"],
        "js": ["jquery.js","scripts.js"]
    }],
    "permissions": [
        "http://*/*"
    ]
}

As you can see I'm loading in a local copy of jQuery, along with another javascript file for my own personal logic. My popup document looks like this:

<select id="values">
    <option>Foo</option>
    <option>Bar</option>
</select>

And the contents of my scripts.js file follow:

$(function(){
  $("#values").change(function(){
    alert("Foo");
  });
});

This isn't doing what I expect though - alerting "Foo" anytime I change a value in my popup HTML. How can I get these two files to communicate with eachother? Or can they at all?

A: 

The content script runs in the context of the loaded page, so that's where it will look for #values. You can't communicate directly between content scripts and the rest of the extension. You'll have to use the messaging API (ready-to-use example on that page).

Max Shawabkeh