开发者

Page JavaScript calling a Firefox extensions JavaScript

开发者 https://www.devze.com 2023-01-25 23:47 出处:网络
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 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

精彩评论

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