call jquery function after page load not working - Firefox extension

我怕爱的太早我们不能终老 提交于 2019-12-13 08:36:30

问题


I've been working on Create Firefox extension. i can inject some js file for all webpages. this function works fine.

codevar myExtension = {
    init: function() {
        // The event can be DOMContentLoaded, pageshow, pagehide, load or unload.
        if(gBrowser) gBrowser.addEventListener("DOMContentLoaded", this.onPageLoad, false);
    },
    onPageLoad: function(aEvent) {
        if ((aEvent.originalTarget.nodeName == '#document') && 
       (aEvent.originalTarget.defaultView.location.href == gBrowser.currentURI.spec)) 
    {
        //alert('loaded');
         var htmlns = "http://www.w3.org/1999/xhtml";
        var doc = gBrowser.selectedBrowser.contentDocument;

          var filerefs = doc.createElementNS(htmlns,'script');
          filerefs.setAttribute("type","text/javascript");
         filerefs.setAttribute("src", "http://code.jquery.com/jquery-1.9.1.min.js");
        doc.getElementsByTagName("head")[0].appendChild(filerefs);

         var filerefst = doc.createElementNS(htmlns,'script');
        filerefst.setAttribute("type","text/javascript");
         filerefst.setAttribute("src", url+"js/tipped/tipped.js");
         doc.getElementsByTagName("head")[0].appendChild(filerefst);    
         filerefst.setAttribute(tripnow());
    }




    }
}
function  tripnow()
{
    //function working fine


    var j = $.noConflict();
            var imageslist = j('img');          
             var output = '';

                     // count image using jquery its not working 

             alert(imageslist.length);

             for (var i = 0, len = imageslist.length; i < len; i++) {        
             var images = j(imageslist).attr('src');
            //alert(images)
              Tipped.create(imageslist[i], "htmlphp.php?id="+i, 
              {
                  ajax: true,
                  skin: 'white',
                  hook: 'topleft',
                  afterUpdate: function() 
                  {
                     Cufon.replace('.HummingbirdDemo h1.museo');
                  }

             });
          }

}

window.addEventListener("load", function load(event){
    window.removeEventListener("load", load, false); //remove listener, no longer needed
    myExtension.init();  
},false);

I want to call my function after script loads. my function call working fine but my inner function script are in jquery its not working.

Main Problem : I want count current page img tags using jquery

Please advise


回答1:


To interact with the page in addon-sdk, you have to use a content script. and you can use jquery on those, but not the way are using it. See Content Scripts



来源:https://stackoverflow.com/questions/18031833/call-jquery-function-after-page-load-not-working-firefox-extension

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