开发者

Page JavaScript calling a Firefox extensions JavaScript

My Firefox开发者_C百科 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜