मैं क्रोम एक्सटेंशन में नया हूं। मैं सामग्री स्क्रिप्ट और पृष्ठभूमि.html पृष्ठ के बीच संवाद करने की कोशिश कर रहा हूं। background.html एक अनुरोध भेजता है, "हैलो", सामग्री स्क्रिप्ट और सामग्री स्क्रिप्ट के लिए "हैलो पृष्ठभूमि" अलर्ट के साथ प्रतिक्रिया देना चाहिए। लेकिन यह अभी नहीं हो रहा है। मेरे background.html कोड है:क्रोम एक्सटेंशन: सामग्री स्क्रिप्ट और background.html के बीच संचार
function testRequest() {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {greeting: "hello"});
});
}
content.js कोड:
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.greeting == "hello")
alert("hello background");
}
);
popup.html कोड:
<!doctype html>
<html>
<head></head>
<body>
<form>
<input type="button" value="sendMessage" onclick="testRequest()" />
</form>
</body>
</html>
manifest.json:
{
"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
},
"background": {
"page": "background.html"
},
"permissions": [
"tabs",
"http://*/*",
"https://*/*",
"notifications",
"contextMenus"
],
"content_scripts": [
{
"matches": ["http://*/*","https://*/*"],
"js": ["content.js"]
}
],
"name": "FirstExtension",
"version": "1.0"
}
कृपया मदद करें!
बहुत रोब धन्यवाद! :) – Chandeep
@ user975234 टेज ['मैसेजेज' पर प्रलेखन] (http://code.google.com/chrome/extensions/extension.html#event-onMessage) वास्तविक स्थिति से मेल नहीं खाता है। अधिक जानकारी के लिए, http://stackoverflow.com/a/11811936 देखें। –