1

I am creating an extension for Chrome. I want to execute a script when the user clicks a button. Here is the code i currently have in my html file

<input type="button" id ="button" onclick='notEmpty()' value="Play"/>

The notEmpty() is in a javascript (.js) file. How can I execute another script in the notEmpty() function?

2 Answers 2

3

I have not written an extension for chrome but for typical javascript you can do one of the following.

<script type="text\javascript">
   function notEmpty()
   {
       someOtherFunction();
   }
</script>

or

<input type="button" id ="button" onclick='notEmpty(); someOtherFunction();' value="Play"/>
Sign up to request clarification or add additional context in comments.

Comments

0

If you want to use functions that are located in another file, you would need to import those files:

<script type="text/javascript" src="/path/to/script.js"></script>

But, in Google Chrome Extensions, if you want to "execute" a script when you click on a button (from an extension page), you can use the chrome.tabs.executeScript functionality

// Run that script on the current tab. The first argument is the tab id.
chrome.tabs.executeScript(null, {file: '/path/to/script.js'});

It all depends on your scenario, when you "executeScript" as shown above, it will inject a content script into that DOM. If you import that script, you will just use those functionality in the current DOM (in that case the extension page, not the tab).

Hope that helped!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.