<\/script>')

Chrome Script Extension Content Creation Not Defined

I write Chrome script content and when I inject it into the DOM:

"<a href='#' onclick='alert(\"Hi!\");return false;'>Hi</a>"

it works fine (a warning appears when I click it), however, if I create a function for the warning, it will say the function is undefined. Example:

"<a href='#' onclick='alertPlease(\"Hi!\");return false;'>Hi</a>"

function alertPlease(x){
     alert(x);
}

All my code is the same contents of the script js file.

Should I post any code that can be used after loading into another js file in the background? I tried adding a wallpaper with 'alertPlease ();' functions, but that didn't work either.

Any hint would be greatly appreciated!
Thank!

+3
source share
2 answers

manifest.json "content_scripts"

{
  "name": "My Extension",
  "content_scripts": [{
    "matches": ["<all_urls>"],
    "css": ["style.css"],
    "js": ["jquery-1.5.js", "script.js"]
  }]
}
-1

Source: https://habr.com/ru/post/1795648/


All Articles