潜在的解决方案是使用“消息传递 API”。
// The ID of the extension we want to talk to.
var id = "abcd..";
// Make a simple request:
chrome.runtime.sendMessage(id, {openUrlInEditor: url},function(response) {
if (!response.success)
handleError(url);
});
在扩展中,您可以通过 runtime.onMessageExternal 或 runtime.onConnectExternal API 收听来自网页的消息,这是一个示例:
chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
if (sender.url == blacklistedWebsite)
return; // don't allow this web page access
if (request.openUrlInEditor)
openUrl(request.openUrlInEditor);
});
来源:http: //developer.chrome.com/extensions/messaging.html
希望能帮助到你!!