如何从HTML按钮调用Firefox扩展的功能 [英] how to call a function in Firefox extension from a html button

查看:143
本文介绍了如何从HTML按钮调用Firefox扩展的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何调用在我的扩展中声明的Javascript函数,使用我的网页上的HTML按钮?

我有一个html页面,里面有一个按钮。当用户点击按钮,它会调用一个函数,我已经在我自己的firefox扩展中声明。

解决方案

网页,最简单和最安全的方法来做你想做的事情就是在网页中发送一个自定义的DOM事件,并在扩展代码中监听它:



https://developer.mozilla.org/En/Code_snippets/Interaction_between_privileged_and_non-privileged_pa​​ges



下面是我写的示例扩展,完全是这个 http://mozilla.doslash.org/cw/ (未更新到最新的Firefox版本,但它很干净,应该很容易更新)。


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.

解决方案

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

这篇关于如何从HTML按钮调用Firefox扩展的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆