मैं कनेक्ट content.js के साथ background.js 2 करने के लिए विभिन्न कार्यों: इंजेक्षन स्थानीय HTML और से डेटा लाने के लिए एक और वेबपेज.
वर्तमान में, createContainer()
के बाद शुरू होता है fetchweb()
किया है और मैं नहीं हूँ यकीन है कि क्यों (मैं की जरूरत है createContainer()
को चलाने के लिए पहली). मैं करने की कोशिश की परिणत करने के लिए दोनों में काम करता है वादा करता हूँ, लेकिन अभी भी एक ही परिणाम
Content.js
function createContainer1() {
// call html file container
chrome.runtime.sendMessage({ cmd: "read_cont1" }, function (html) {
$("#container1").html(html);
});
// more code
}
function fetchWeb() {
chrome.runtime.sendMessage(
{ cmd: "send_url", url: window.location.href},
function (response) {
console.log(JSON.stringify(response));
}
);
}
createContainer1()
fetchWeb()
background.js
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.cmd == "read_cont1") {
$.ajax({
url: chrome.extension.getURL("container1.html"),
dataType: "html",
success: sendResponse,
});
return true;
} else if (request.cmd == "send_url") {
sendResponse({ review_url: fetchData(request.url) });
return true;
}
});