Skip to content

Instantly share code, notes, and snippets.

@dascgo
Created March 21, 2011 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dascgo/880361 to your computer and use it in GitHub Desktop.
Save dascgo/880361 to your computer and use it in GitHub Desktop.
// load in our tools
var tabs = require("tabs");
var data = require("self").data;
// when someone goes to a tab:
tabs.on('activate', function(tab){
tab.attach({
// attach the tab.js file
contentScriptFile: data.url("tab.js"),
// and handle messages coming FROM tab.js
onMessage: function(data){
if(data.type == "click"){
// do some stuff, then post back to the tab
this.postMessage({
"type": "click_complete",
"msg": "thanks for clicking the button!"
});
}else{
console.log("unknown message from TAB: " + data.toSource());
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment