如何在html中使用onclick调用firefox插件函数 [英] How to call firefox addon function with onclick in html

查看:108
本文介绍了如何在html中使用onclick调用firefox插件函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一个程序,用正则表达式扫描电话号码。然后,如果它匹配,应该基本上添加一个图像到应该点击的电话号码的后面,然后在我的Firefox扩展中调用我的功能。

  onDialerHandler:function(number){
alert(onclick Event detected!);
$,
$ b $ onPageLoad:function(aEvent){
if(aEvent.originalTarget.nodeName ==#document){
var doc = aEvent.originalTarget ;

var regex = / \(?([0-9] {3})\)?[ - 。 ]([0-9] {3})[? - 。 ]([0-9] {4})/克?;

var contents = doc.body.innerHTML;

var idx = contents.search(hello);
if(idx){
var candidates = content.match(regex);

content = content.replace(regex,'($ 1)$ 2- $ 3< input id =testbuttontype =imagesrc =chrome:// click2dial / content / images / call ()width =15height =15>');
doc.body.innerHTML = contents;



code $
$ b我还是很新的Firefox的插件和JavaScript。这是我发现添加图像的一种方式,但我无法处理onclick。



我已经阅读过使用createElement的人,但是我只是无法正常工作。

如果有任何身体可以帮我用代码添加我的点击图像我的正常表达匹配的背面。一个人的图像被点击的功能onDialerHandler需要被调用。

我相信我不需要使用.replace函数得到这个工作的帮助。即使把我指向正确的方向可能会帮助我分配?

解决方案

您应该在页面中创建一个自定义事件并分派它。

  
var evt = document.createEvent(Events);
evt.initEvent(MY_EVENT,true,false);
document.dispatchEvent(evt);

在扩展端,您应该创建一个侦听器来捕获事件。

  
document.addEventListener(MY_EVENT,myFunction,false,true);

如果您想传递某个日期,您可以为此用户事件

  
var evt = document.createEvent(Events);
evt.someDate =date;
....


I am trying to write a program that scans for phone numbers with a regular expression. Then if it matches it should basically add an Image to the back of the phone number that should be click able and then call my function in my Firefox extension.

onDialerHandler: function(number){
  alert("onclick Event detected!");
},

onPageLoad : function(aEvent) {
if(aEvent.originalTarget.nodeName=="#document"){
  var doc = aEvent.originalTarget;

  var regex = /\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})/g;      

  var contents=doc.body.innerHTML;  

  var idx=contents.search("hello");
  if(idx) {
    var candidates = contents.match(regex);

    contents=contents.replace(regex,'($1) $2-$3<input id="testbutton" type="image" src="chrome://click2dial/content/images/call.png" name="image" onclick="onDialerHandler()"  width="15" height="15">');
    doc.body.innerHTML=contents;
    }  
  }
},

I am still very new to firefox addons and javascript. This is one way I have found to add the image but I am not able to process the onclick.

I have read up on people using "createElement" but I am just not able to get it working.

If there is any body that can help me with code to add my click able image the back of my regular expressing matches. One's the images is clicked the function onDialerHandler needs to be called.

I do believe I need help in not using the .replace function to get this working. Even pointing me in the right direction might help me allot?

解决方案

You should create a custom event in page and dispatch it.


  var evt = document.createEvent("Events");
  evt.initEvent("MY_EVENT", true, false);
  document.dispatchEvent(evt);

on extension side you should create a listener to catch event.


document.addEventListener("MY_EVENT", myFunction, false, true);

If you want to pass some date, you can user event for this


  var evt = document.createEvent("Events");
  evt.someDate = "date";
 ....

这篇关于如何在html中使用onclick调用firefox插件函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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