2

My Firefox extension has a button which when clicked, injects some JavaScript code into the current page. How can this injected JavaScript code in a web-page call a JavaScript function in my extension? It would be helpful if someone could point me to an example.

Thanks.

3
  • 1
    Duplicate of stackoverflow.com/questions/4215507/… ? Commented Nov 21, 2010 at 17:50
  • That's his own question + the accepted answer is his own? Commented Nov 21, 2010 at 17:57
  • I did post a question a day or two back but if you read through it, you'll see that it was about invoking a script function from the extension and this is the other way around. Commented Nov 21, 2010 at 18:53

1 Answer 1

4

It boils down to dispatching events from the document object and listening for them from your extension. You must create a listener for these events on a per-tab basis. You may also be able to catch them using jQuery embedded in your extension.

The simplest way to do this is outlined here:

https://developer.mozilla.org/en/Code_snippets/Interaction_between_privileged_and_non-privileged_pages

You can set up a JS library (on your page) and a matching library in your extension that allows you to do exactly this in a repeatable way.

Sign up to request clarification or add additional context in comments.

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.