how to call a function in Firefox extension from a html button

user186889 picture user186889 · Jan 7, 2010 · Viewed 7.1k times · Source

How to call a Javascript function declared in my extension, using a html button from my web page?

I have a html page, with a button inside. When the user click the button, it will call a function that I already declared inside my own firefox extension.

Answer

Nickolay picture Nickolay · Jan 7, 2010

Since you control the web page, the easiest and the safest method to do what you want would be to dispatch a custom DOM event in the web page and listen to it in the extension code:

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

Here's an example extension I wrote that does exactly this http://mozilla.doslash.org/cw/ (not updated to the most recent Firefox version, but it's clean and should be easy to update).