So, I have trouble. I am making a chrome extension, I have popup.html (window with credits), content.js, background.js (that works on click). Main trouble is that when I click on icon of extension background.js getting that I clicked it and starts working on popup page and not on the page I needed. I've tried to make it in popup.js, but same thing, it is working in popup.html page and not on the main page. How to change js code?
Main part of content.js:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "clicked_browser_action" ) {
var name = window.location.href;
subject = name.substr(name.indexOf("/",1)+2,name.indexOf("-",1)-name.indexOf("/",1)-2);
exam = name.substr(name.indexOf("-",1)+1,name.indexOf(".",1)-name.indexOf("-",1)-1);
myLoop();
}
}
);
background.js:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "clicked_browser_action"});
});
});