Re: nsIDocumentObserver bug (maybe).

Mark Hammond <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xpcom
Organization Another Netscape Collabra Server User
Message-ID <[email protected]>
Michael A. Borisov wrote:
> Hello everybody,
> 
> Can anybody help me with DocumentObserver please? I've created a child of
> nsIDocumentObserver than registered it with the nsIDocument::AddObserver
> method. I use BeginLoad and EndLoad methods to determin the start and end of
> document loading. But sometimes EndLoad isn't invoked (for some sites). Is
> it bug or feature? And what is the right way to determin the document
> loading end?

You probably want nsIWebProgress.  Here is code I used to hook document 
load.

// hook a web progress listener so we know when messages have
// finished rendering.
var interfaceRequestor =
     document.getElementById('messagepane').docShell.QueryInterface
    (Components.interfaces.nsIInterfaceRequestor);
var webProgress =
    interfaceRequestor.getInterface(
       Components.interfaces.nsIWebProgress);
msgWindowWebProgressListener = new nsMsgWindowWebProgressListener();
webProgress.addProgressListener(msgWindowWebProgressListener,
              Components.interfaces.nsIWebProgress.NOTIFY_STATE_WINDOW);

And the implementation:

function nsMsgWindowWebProgressListener()
{
}
nsMsgWindowWebProgressListener.prototype =
{
   QueryInterface : function(aIID) {
     if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
         aIID.equals(Components.interfaces.nsISupportsWeakReference))
       return this;
    throw Components.results.NS_NOINTERFACE;
  },
   onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus) {
     if ((aStateFlags & ListenerState_Finished) == ListenerState_Finished) {
...
}
}

HTH,

Mark.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.