3

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

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

4

1 回答 1

2

覆盖.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);

内容.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);
于 2011-12-07T09:04:24.740 回答