views:

263

answers:

2

How can I know the url under the mouse cursor from a firefox extension?

I need to interact with the href from within the overlay.js file.

I'd want a lightweight solution, for example I don't want to attach some event to all hrefs found in a page.

I'd rate a mouseover solution but how can't find anything useful for me!

Thanks

+2  A: 

You don't really have a choice but to attach an event to all anchor tags on a page. Sorry.

sdwilsh
+3  A: 

You could use event delegation and attach single event listener to the document.body element, instead of all hrefs on the page. Then you need to check if the element which triggered your listener is a link or not. Here's a simple example that demonstrates the idea:

document.body.addEventListener( 'mouseover', 
    function(e){ 
        if(e.target.nodeName=='A'){ alert( e.target.href ) }
    }, false);
pawel