title: Detect page load completed event in Firefox
body: <p>I'm writing a Firefox add-on that do something after the webpage is completely loaded.<br>My current code is</p>
  
  <pre><code>var target = this;
      const STATE_STOP = Components.interfaces.nsIWebProgressListener.STATE_STOP;
      const STATE_IS_WINDOW = Components.interfaces.nsIWebProgressListener.STATE_IS_WINDOW;
      const STATE_IS_DOCUMENT = Components.interfaces.nsIWebProgressListener.STATE_IS_DOCUMENT;
      const locationChangeListener = {
          onStatusChange: function(){},
          onProgressChange: function(){},
          onLocationChange: function(aWebProgress, aRequest, aLocation){},
          onStateChange: function(aWebProgress, aRequest, aFlag, aStatus){
              if((aFlag &amp; STATE_STOP) &amp;&amp; (aFlag &amp; STATE_IS_WINDOW)){
  
  
                  //Do something in here
  
  
              }
          },
          onSecurityChange: function(){}
      };
      gBrowser.addProgressListener(locationChangeListener);
  </code></pre>
  
  <p>It works fine. But sometimes, for example webpage with AJAX call, this event fired several times for one web page.</p>
  
  <p>Is there any way to detect if the webpage is completely loaded or not?</p>