在页面加载不工作后调用jquery函数 - Firefox扩展 [英] call jquery function after page load not working - Firefox extension

查看:118
本文介绍了在页面加载不工作后调用jquery函数 - Firefox扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在创造Firefox扩展。我可以为所有网页注入一些js文件。这个函数可以正常工作。

$ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $事件可以是DOMContentLoaded,pageshow,pagehide,加载或卸载。
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());






函数tripnow()
{
//函数工作正常


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

//使用jquery计数图片无效

alert(imageslist.length); (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,
皮肤:'white',
hook:'topleft',
afterUpdate:function()
{
Cufon.replace('。HummingbirdDemo h1.museo');
}

});



$ b window.addEventListener(load,function load(event){
window.removeEventListener(load,load, false); //删除监听器,不再需要
myExtension.init();
},false);

我想在脚本加载后调用我的函数。我的函数调用工作正常,但我的内部函数脚本在jquery中不起作用。

主要问题:我想要使用jquery计算当前页面的img标签



请指教

解决方案

-sdk,你必须使用内容脚本。你可以在这些上使用jquery,但不是使用它的方式。请参阅内容脚本


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

解决方案

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

这篇关于在页面加载不工作后调用jquery函数 - Firefox扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆