javascript - Firefox Add-on SDK: communicating objects between a sidebar and the main script -


i hacking away @ first addon, problem running has either obvious solution or general approach flawed.

i using add-on sdk. lib/main.js contains object foo. data directory has files sidebar.html , sidebar.js. want pass foo sidebar-script , change sidebar depending on state of foo. in minmal example try display object.

minimal example:

main.js:

var foo = {"a": "b", "c": "d"}; var bar = require("sdk/ui/sidebar").sidebar({     id: "sb",     title: "foobar",     url: "./sidebar.html" }); bar.show(); 

sidebar.html:

<!doctype html> <html>     <body>                 <div id="foo-here">             <!-- modified sidebar.js -->         </div>     </body>     <script type="text/javascript" src="sidebar.js"></script> </html> 

sidebar.js:

var foodiv = document.getelementbyid("foo-here"); var str = "", o; // magically foo main.js here (o in foo) {     if (foo.hasownproperty(o)) {         str += "[" + o + " " + foo[o] + "]";     } } foodiv.innerhtml = str; 

the sidebar docs explain how listen signals main script , call function upon receiving signal, can't figure out how pass object itself.

the port.emit() api mentioned in sidebar docs have linked takes second argument pass in objects.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -