I
I
ibr_982018-02-18 17:42:40
JavaScript
ibr_98, 2018-02-18 17:42:40

How can I make the script in "content_scripts" be executed in the chrome api so that when the button in "popup.html" is clicked?

Hello!
here is the code snippet in manifest.json :

"content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["jquery.js", "script.js"]
    }
  ]

code in script.js itself :
alert('hello')
code in popup.html :
<button>alert</button>
I want to run the code in scritp.js when I click on the alert button . PS I tried to include the script.js file in popup.html , but it only worked in the popup itself, that is, the window with the word hello popped up in popup.html itself , but the window didn’t pop up on the page I was on .. I would be grateful for your help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hOtRush, 2018-02-19
@hOtRush

If I remember correctly, content_scripts are scripts that are embedded in a page in an open tab, and popup.html is a different page, and it has different scripts. Communication between these pages must be done in other ways https://developer.chrome.com/apps/messaging

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question