Created
December 26, 2012 19:15
-
-
Save 0xjjpa/4382370 to your computer and use it in GitHub Desktop.
Basic communication between a Background Page and a Content Script inside a Chrome Extension.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In Background.js | |
chrome.tabs.sendMessage(tab.id, {content: "message"}, function(response) { | |
if(response) { | |
//We do something | |
} | |
}); | |
// In ContentScript.js | |
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { | |
if(request.content) { | |
sendResponse({content: "response message"}); | |
return true; // This is required by a Chrome Extension | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment