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

后端 未结 3 694
心在旅途
心在旅途 2021-01-04 22:52

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

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-04 23:22

    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).

提交回复
热议问题