Load event listener does not working for one tab.. - Mozilla

This is a discussion on Load event listener does not working for one tab.. - Mozilla ; hi, i have a problem, in my extension i can found out all tabs but not the first one and if i have only one tab, i cannot watch its location change or sth else.. please help me.. here is ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Load event listener does not working for one tab..

  1. Load event listener does not working for one tab..

    hi,

    i have a problem, in my extension i can found out all tabs but not the
    first one and if i have only one tab, i cannot watch its location
    change or sth else.. please help me..

    here is the code:

    window.addEventListener("load", function(e) { InitialWindow(); },
    false);
    window.addEventListener("unload", function(e) { UnloadWindow(); },
    false);

    function InitialWindow() {
    var container = gBrowser.tabContainer;
    container.addEventListener("TabOpen", OnTabOpen, false);
    container.addEventListener("TabMove", OnTabMove, false);
    container.addEventListener("TabClose", OnTabClose, false);

    }

    function UnloadWindow() {
    var container = gBrowser.tabContainer;
    container.removeEventListener("TabOpen", OnTabOpen, false);
    container.removeEventListener("TabMove", OnTabMove, false);
    container.removeEventListener("TabClose", OnTabClose, false);
    }

    function onTabSelected(event)
    {
    var browser = event.target.linkedBrowser;
    browser.addProgressListener(toolbarListener);
    }
    function OnTabOpen(event)
    {
    var browser = event.target.linkedBrowser;
    browser.addProgressListener(toolbarListener);

    }

    function OnTabMove(event)
    {
    var browser = event.target.linkedBrowser;
    }

    function OnTabClose(event)
    {
    var browser = event.target.linkedBrowser;
    browser.removeProgressListener(toolbarListener);
    }
    var toolbarListener =
    {
    QueryInterface: function(aIID)
    {
    if ( aIID.equals(Components.interfaces.nsIWebProgressLi stener) ||
    aIID.equals(Components.interfaces.nsISupportsWeakR eference) ||
    aIID.equals(Components.interfaces.nsISupports) )
    {
    return this;
    }

    throw Components.results.NS_NOINTERFACE;
    },

    onStateChange: function(aWebProgress, aRequest, aFlag, aStatus)
    {
    if(aFlag & STATE_START)
    {
    OnLoadInitiated(aWebProgress, aRequest);
    }

    if(aFlag & STATE_STOP)
    {
    alert("Load Event Finished.");
    }

    return 0;
    },

    onLocationChange: function(aProgress, aRequest, aURI)
    {
    OnLocationChange(aProgress, aRequest, aURI);
    return 0;
    },

    onProgressChange: function(aWebProgress, aRequest, curSelf, maxSelf,
    curTot, maxTot) { return 0;},
    onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)
    { return 0;},
    onSecurityChange: function(aWebProgress, aRequest, aState) { return
    0;}
    };

  2. Re: Load event listener does not working for one tab..

    On 28 авг, 13:06, otekin wrote:
    > hi,
    >
    > i have a problem, in my extension i can found out all tabs but not the
    > first one and if i have only one tab, i cannot watch its location
    > change or sth else.. please help me..
    >
    > here is the code:
    >
    > window.addEventListener("load", function(e) { InitialWindow(); },
    > false);
    > window.addEventListener("unload", function(e) { UnloadWindow(); },
    > false);
    >
    > function InitialWindow() {
    > * * var container = gBrowser.tabContainer;
    > * * container.addEventListener("TabOpen", OnTabOpen, false);
    > * * container.addEventListener("TabMove", OnTabMove, false);
    > * * container.addEventListener("TabClose", OnTabClose, false);
    >
    > }
    >
    > function UnloadWindow() {
    > * * var container = gBrowser.tabContainer;
    > * * container.removeEventListener("TabOpen", OnTabOpen, false);
    > * * container.removeEventListener("TabMove", OnTabMove, false);
    > * * container.removeEventListener("TabClose", OnTabClose, false);
    >
    > }
    >
    > function onTabSelected(event)
    > {
    > * * * * var browser = event.target.linkedBrowser;
    > * * * * browser.addProgressListener(toolbarListener);}
    >
    > function OnTabOpen(event)
    > {
    > * * * * var browser = event.target.linkedBrowser;
    > * * * * browser.addProgressListener(toolbarListener);
    >
    > }
    >
    > function OnTabMove(event)
    > {
    > * * * * var browser = event.target.linkedBrowser;
    >
    > }
    >
    > function OnTabClose(event)
    > {
    > * * * * var browser = event.target.linkedBrowser;
    > * * * * browser.removeProgressListener(toolbarListener);}
    >
    > var toolbarListener =
    > {
    > * * * * QueryInterface: function(aIID)
    > * * * * {
    > * * * * * * * * if ( * aIID.equals(Components.interfaces.nsIWebProgressLi stener) ||
    > * * * * * * * * * * * * * * * * aIID.equals(Components.interfaces.nsISupportsWeakR eference) ||
    > * * * * * * * * * * * * * * * * aIID.equals(Components.interfaces.nsISupports) * )
    > * * * * * * * * * * * * {
    > * * * * * * * * * * * * * * * * return this;
    > * * * * * * * * * * * * }
    >
    > * * * * * * * * throw Components.results.NS_NOINTERFACE;
    > * * * * },
    >
    > * * onStateChange: function(aWebProgress, aRequest, aFlag, aStatus)
    > * * * * {
    > * * * * * * * * if(aFlag & STATE_START)
    > * * * * * * * * {
    > * * * * * * * * * * * * OnLoadInitiated(aWebProgress, aRequest);
    > * * * * * * * * }
    >
    > * * * * * * * * if(aFlag & STATE_STOP)
    > * * * * * * * * {
    > * * * * * * * * * * * * alert("Load Event Finished.");
    > * * * * * * * * }
    >
    > * * * * * * * * return 0;
    > * * * * },
    >
    > * * * * onLocationChange: function(aProgress, aRequest, aURI)
    > * * * * {
    > * * * * * * * * OnLocationChange(aProgress, aRequest, aURI);
    > * * * * * * * * return 0;
    > * * * * },
    >
    > * * * * onProgressChange: function(aWebProgress, aRequest, curSelf, maxSelf,
    > curTot, maxTot) { return 0;},
    > * * * * onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)
    > { return 0;},
    > * * * * onSecurityChange: function(aWebProgress, aRequest, aState) { return
    > 0;}
    >
    > };


    i suppose you should add this to window onload event

    for (var i=0; i gBrowser.getBrowserForTab(container.getItemAtIndex (i))
    addProgressListener(toolbarListener); ;
    }

    some tabs can be already created before you install event listener.

+ Reply to Thread