2013-08-03 85 views
0

我一直在努力創建Firefox擴展。我可以爲所有網頁注入一些js文件。這個功能工作正常。頁面加載失敗後調用jquery函數 - Firefox擴展

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

我想在腳本加載後調用我的函數。我的函數調用工作正常,但我的內部函數腳本在jquery中不起作用。

主要問題:我想使用jQuery

請告知

+0

您不需要將jquery添加到頁面以在擴展上使用它。這不是它的工作原理。你使用的是firefox-addon-sdk嗎? –

+0

@FilipeSilva是的席爾瓦我很困惑。我需要爲所有圖像顯示工具提示。這是我的補充我嘗試我的本地HTML文件的工作,但不幸的是,我實現了我的補充其不工作 –

+0

我的HTML頁面鏈接:http://demo.osiztechnologies.com/superfish/main/testingfinal.html –

回答

0

要在插件-SDK頁面交互計算當前頁面的img標籤,你必須使用一個內容腳本。你可以在這些上使用jquery,但不是使用它的方式。請參閱Content Scripts

相關問題