The code that I previously posted was not complete.
To review, I am trying to temporarily disable links in
my embedded app. The following code snippet attempts
to do just that:

    nsCOMPtr<nsIDOMHTMLCollection> links;
    domdoc->GetLinks(getter_AddRefs(links));

    PRUint32 numnodes;
    links->GetLength(&numnodes);

    nsCOMPtr<nsIDOMNode> link;
    for (unsigned int i = 0; i < numnodes; i++)
    {
        links->Item(i, getter_AddRefs(link));

        nsCOMPtr<nsIDOMHTMLImageElement>    image =
(do_QueryInterface(link));
        nsCOMPtr<nsIDOMHTMLLinkElement>     alink =
(do_QueryInterface(link));
        nsCOMPtr<nsIDOMHTMLAnchorElement>   anchor =
(do_QueryInterface(link));

        if (image) printf("node is image\n");
        else if (alink) alink->SetDisabled(FALSE);
        else if (anchor) printf("node is anchor\n");
    }

I have found that all links in the collection are considered of type
nsIDOMHTMLAnchorElement. This is not the behavior I expected.
If anyone has a solution to this problem, please let me know. Thanks.

John Stewart

John Stewart wrote:

> I am trying to figure out a way to disable links in my embedded app, and
> I have been unsuccessful. After some investigation, I would have thought
> the following code snippet to be a solution to my problem:
>
>     nsCOMPtr<nsIDOMHTMLDocument> domdoc;
>     rv = doc->QueryInterface(nsIDOMHTMLDocument::GetIID(),
>                              getter_AddRefs(domdoc));
>
>     if (NS_FAILED(rv)) return;
>
>     nsCOMPtr<nsIDOMHTMLCollection> links;
>     domdoc->GetLinks(getter_AddRefs(links));
>
>     PRUint32 numnodes;
>     links->GetLength(&numnodes);
>
>     nsCOMPtr<nsIDOMNode> link;
>     for (unsigned int i = 0; i < numnodes; i++)
>     {
>         // The following line does not produce the correct result. The
> elements in the
>         // collection are of the type nsIDOMHTMLAnchorElement...
>         nsCOMPtr<nsIDOMHTMLLinkElement>     alink =
> (do_QueryInterface(link));
>
>         alink->SetDisabled(FALSE);
>     }
>
> If anyone knows of a solution to this problem, I would appreciate
> hearing from you. Thanks.
>
> John Stewart


Reply via email to