Firefox附加组件的HTML页面单击功能

时间:2014-04-10 09:06:50

标签: javascript jquery html firefox-addon firefox-addon-sdk

场景:加载项检测网页上的电话号码,并通过超链接突出显示。当用户点击该号码时,它应该打开一个新的弹出窗口,要求登录系统。

问题:

无法在鼠标点击时打开html页面。以下是代码

代码

main.js

var {data} = require("sdk/self");
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*",
attachTo: ["top"],

contentScriptFile: [data.url("jquery-2.1.0.js"),data.url("script.js")]
});
var myPanel = require("sdk/panel").Panel({
contentURL: self.data.url("page.html")
});
myPanel.show();

script.js

 var regex = /\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/g;

 jQuery.fn.linker = function () {
    //var regex = /\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/g;
 $(this).contents()
    .filter(function() { return this.nodeType !== Node.TEXT_NODE; })
    .each(function () { $(this).linker(); });
 $(this).contents()
    .filter(function() { return this.nodeType === Node.TEXT_NODE; })
    .each(function () {
        $(this).replaceWith(
            $(this).text().replace(regex,"<a href=\"\">$&</a>")
        );
    });
 };
 $(document).ready(function () {
 $('body').linker();

 $( 'a' ).click( function () {
 var href = $(this).text();
    //alert(href);

    var tel = regex.test(href);
    if ( tel ) {
        //alert( 'A telephone link was clicked: ');
        href = href.replace(/[(]\d[)]|[. -]/g,'');
        //alert(href);
        //event.preventDefault();
        window.open($(this).attr('href'),"popupWindow","width = 600,height=600,scrollbars=yes");
    }
});
});

0 个答案:

没有答案
相关问题