title: Load a set of URL's with document.location.href and then execute JS only if the page was loaded
body: <p>I'm doing a FireFox extensions. I have an array of URL's. What I want is: redirect the page with <code>document.location.href</code> for all the URL's that I have and then, with a XPath that I have, count the number of elements that the page has.</p>
  
  <p>The problem is that I have to wait that the page load was finish before execute the count method with the XPath. This is my code:</p>
  
  <pre><code>var actualResult = 0;
  actualResult = content.document.evaluate('count('+taskModeler.ui.getStatus()+')', content.document, null, XPathResult.NUMBER_TYPE, null).numberValue; 
  for(var i=0; i&lt;taskModeler.ui.getPageContent().length;i++) {
      content.document.location.href = taskModeler.ui.getPageContent()[i].getAttribute("href");
     //only if the page was loaded execute the next line
  
     actualResult+=content.document.evaluate('count('+taskModeler.ui.getStatus()+')',
         content.document, null, XPathResult.NUMBER_TYPE, null).numberValue; 
  }
  </code></pre>
  
  <p><code>getPageContent()</code> returns an array that contains a <strong>set of URL's</strong>. For each of these URL's I have to load the page to get acces to the document and then count the occurrences that returns the XPath. But if the page not was loaded the count method doesn't work because returns the results of the actual page, not the page that was loaded in <code>content.document.location</code>.</p>
  
  <p>How can I do that?</p>