On Sep 24, 9:49 pm, Boris Zbarsky <[EMAIL PROTECTED]> wrote:
> Brightman wrote:
> > thank u very much!
> > "a" or "A", the length of nodelist is 0
>
> > but GetElementsByTagName(NS_LITERAL_STRING("body"),....),
> > nodelist->GetLength()  return 1.
>
> When is this code running?  What is mNavigation?
>
> -Boris

this code is based on EmbedPrivate.cpp (mozilla/embedding/browser/gtk/
src)

as following:

void
EmbedPrivate::LoadCurrentURI(void)
{
  if (mURI.Length()) {
    nsCOMPtr<nsPIDOMWindow> piWin;
    GetPIDOMWindow(getter_AddRefs(piWin));

    nsAutoPopupStatePusher popupStatePusher(piWin, openAllowed);

    mNavigation->LoadURI(mURI.get(),                        // URI
string
                         nsIWebNavigation::LOAD_FLAGS_NONE, // Load
flags
                         nsnull,                            //
Referring URI
                         nsnull,                            // Post
data
                         nsnull);                           // extra
headers
  }
  /*add by brightman*/
  //get current document
  nsCOMPtr<nsIDOMDocument> domDoc;
  nsresult res = mNavigation->GetDocument(getter_AddRefs(domDoc));
  //NS_ENSURE_TRUE(domDoc, nsnull);
  printf("Get Document \n");
  nsCOMPtr<nsIDOMNodeList> nodelist;
  res = domDoc-
>GetElementsByTagName(NS_LITERAL_STRING("a"),getter_AddRefs(nodelist));
  PRUint32 index;
  PRUint32 length;
  res = nodelist->GetLength(&length);
  printf("Get nodelist num[%d] res[%d]\n",length,res);
  NS_NAMED_LITERAL_STRING(hrefAttr,"href");
  for(index=0;index<length;index++)
  {
    nsCOMPtr<nsIDOMNode> node;
    res=nodelist->Item(index,getter_AddRefs(node));
    nsAutoString href;
    nsCOMPtr<nsIDOMElement> elt = do_QueryInterface(node);
    res = elt->GetAttribute(hrefAttr,href);
    printf("node[%d] %s res[%d]\n",index,href.get(),res);
 }
}

_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to