How to use jQuery in content script in a Firefox Mobile (Fennec) extension?

[亡魂溺海] 提交于 2020-01-04 04:04:11

问题


I am developing a Firefox Mobile (Fennec) extension and I want to use jQuery in the content script. What is the best way to do it?

I am doing the testing on the desktop version of Firefox Mobile 4


回答1:


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);


来源:https://stackoverflow.com/questions/8376416/how-to-use-jquery-in-content-script-in-a-firefox-mobile-fennec-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!