I want to create an extension in Firefox that extracts links embedded on a web page from users moving the mouse on the link. This would be very similar to link target display on the status bar at the bottom of the browser.
The problem I am having is getting access to document object of the loaded webpage. I tried document.getElementsByTag("a") it didn’t work. I tried content.document.getElementByTag("a") it didn’t work.
Ideally I want it to behave like this:
- webpage is loaded.
- all anchors on the web page are assigned attribute onmouseover.
- user points to a link.
- the event is triggered and the link’s url is extracted and displayed on a alert box.
A few things:
documentis the document of the browser, not of a webpage, so you do wantcontent.document.getElementsByTagName. Use the error console — it should tell you thatgetElementsByTagis not a function.content.document.linksif (event.target instanceof HTMLAnchorElement)or something to see if it’s a link.unloadevent).