如何在Firefox Mobile(Fennec)扩展中的内容脚本中使用jQuery?

时间:2011-12-04 15:43:53

标签: jquery firefox mobile firefox-addon fennec

我正在开发Firefox Mobile(Fennec)扩展,我想在内容脚本中使用jQuery。 最好的方法是什么?

我正在对桌面版的Firefox Mobile 4进行测试

1 个答案:

答案 0 :(得分:2)

<强> overlay.js中

window.addEventListener("load", function (aEvent){
    document.getElementById("browsers").addEventListener("DOMContentLoaded", function onWindowLoad(aEvent){
        window.messageManager.loadFrameScript("chrome://myExtension/content/jquery.js", true);
        window.messageManager.loadFrameScript("chrome://myExtension/content/content.js", true);
}, false);

<强>的jquery.js

addEventListener('DOMContentLoaded', function(event) {
    with(content){
        /* jQuery core code goes here */
    }
}, true);

<强> content.js

addEventListener('DOMContentLoaded', function(aEvent) { // on page load
    with(content) {
         if (aEvent.originalTarget.location.href != null) {
             if (aEvent.originalTarget.location.href == document.location.href && document.location.href != 'about:home') {
                //alert(jQuery(document).attr('title') + '\n' + jQuery(location).attr('href'));
             }
         }
    }
}, true);