0

I am trying to run JavaScript functions on someone else's website using a button in my Chrome Extension.

In my HTML file, I have a button:

<input id="form-save" type="submit" value="Start" />

I would like to run a function that will first check if the website I'm on is a certain website, and will then run a function on that website such as:

function reload_page() {
    location.reload();
}

I have got code to run inside of my extension using:

// Pure JS:
document.addEventListener('DOMContentLoaded', function() {
  document.getElementById("click-this").addEventListener("click", handler);
});

// The handler also must go in a .js file
function handler() {
  /* ... */
}

which I got from onClick within Chrome Extension not working.

Although, I cannot get any code to run on the website I'm actually on in Chrome.

Any help would be greatly appreciated, thanks.

F J
  • 48
  • 1
  • 8
  • You need a [content script](https://developer.chrome.com/extensions/content_scripts). – wOxxOm Dec 11 '17 at 21:33
  • @wOxxOm Thanks for your reply, would you be able to give me an example of the code I'd need to do what I said in my post? I'm very new to chrome extensions so I'm not really sure how to do it – F J Dec 11 '17 at 23:58
  • You can find lots of examples using google. See also the official ones: https://developer.chrome.com/extensions/samples – wOxxOm Dec 12 '17 at 00:07
  • @wOxxOm I know but as I've said I really don't know what any of that means, so could you please write out the full code using my example? Thanks – F J Dec 12 '17 at 13:50
  • Asking for code answers is bad practice for Stack Overflow, on top of that, code only answers are also considered bad answers. In addition, you're literally asking for someone else to do your own work... – brandito Aug 21 '18 at 06:39

0 Answers0