Re: Can I get document.links in JavaXPCOM ?

Carfield Yim <[email protected]> Thu, 21 Jun 2007 16:30:05 -0000
Newsgroups gmane.comp.mozilla.devel.java
Organization http://groups.google.com
Message-ID <1182443405.491719.11670__26426.7052909874$1182443420$gmane$org@j4g2000prf.googlegroups.com>
On 6 17 ,   11 33 , Michal Ceresna <[email protected]> wrote:
> On Sunday 17 June 2007, Carfield Yim wrote:
> Hello,
>
> > Can I get the list of links with document.links in JavaXPCOM?
>
> sure,
>
> nsIDOMDocument doc = ...;
> nsIDOMHTMLDocument htmlDoc = (nsIDOMHTMLDocument) doc.queryInterface(nsIDOMHTMLDocument.NS_IDOMHTMLDOCUMENT_IID);
> nsIDOMHTMLCollection links = htmlDoc.getLinks();
>
> best regards,
> Michal

Thanks , now I can get document.links and link.href. However, it is
just relative links like what I get from getElementByTagName("a") .
Can I get absolute links?

More specific, I run the following code:

                                                        final
nsIDOMHTMLDocument htmlDoc = (nsIDOMHTMLDocument)
doc.queryInterface(nsIDOMHTMLDocument.NS_IDOMHTMLDOCUMENT_IID);
                                                        final
nsIDOMHTMLCollection list = htmlDoc.getLinks();
                                                        final
List<String> links = new ArrayList<String>();
                                                        for (int i =
0; i < list.getLength(); i++) {
                                                                final
String nodeValue = list.item(i).getAttributes()
                                                                                .getNamedItem("href").getNodeValue();
 
links.add(nodeValue);
 
System.out.println(nodeValue);
                                                        }

What I get is

archiver/
archiver/?fid-9.html
archiver/?tid-305790.html
archiver/?tid-364135.html

but what I need is

http://www.xxx.net/archiver/
http://www.xxx.net/archiver/?fid-9.html
http://www.xxx.net/archiver/?tid-305790.html
http://www.xxx.net/archiver/?tid-364135.html