如何在html中使用onclick调用firefox插件函数
我正在尝试编写一个程序,使用正则表达式扫描电话号码。然后,如果它匹配,它基本上应该在电话号码的后面添加一个图像,该图像应该可以点击,然后在我的 Firefox 扩展中调用我的函数。
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;
}
}
},
我对 Firefox 插件和 javascript 还很陌生。这是我发现添加图像的一种方法,但我无法处理 onclick。
我已经阅读了有关使用“createElement”的人的资料,但我无法使其正常工作。
如果有任何机构可以帮助我编写代码,将可点击的图像添加到我的常规表达匹配的背面。单击图像后需要调用 onDialerHandler 函数。
我确实相信我需要帮助才能不使用 .replace 函数来使其正常工作。即使为我指明正确的方向也可能会帮助我分配?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在页面中创建一个自定义事件并调度它。
在扩展端,您应该创建一个侦听器来捕获事件。
如果您想传递某个日期,您可以为此使用用户事件
You should create a custom event in page and dispatch it.
on extension side you should create a listener to catch event.
If you want to pass some date, you can user event for this