...

View Full Version : How to extract target of an anchor under mouse pointer



pc131
09-30-2011, 10:19 AM
I am trying to redevelop firefox addon, to give it more funcionality. I found JS file where all the functions are and started to edit it.

What I want to achieve is to get target of an anchor under mouse pointer (when mouse pointer is over anchor, I right click and call addon from context menu).

For example when I have anchor which HTML code is:


<a href="somewehere.com/place">place</a>

when I right click on this code and call my addon I would like to alert its href (somewehere.com/place)

I wrote a function:



function ff()
{
var current_target=this.href;
alert(current_target);
}

but it gives me udefined on alert

http://i56.tinypic.com/au7gk1.png

Any hints to achieve this are highly appreciated.

Thanks

Philip M
09-30-2011, 11:03 AM
<a href="http://www.google.com" onclick = "ff(this)">place</a>

<script type = "text/javascript">
function ff(which) {
var current_target=which.href;
alert(current_target);
}
</script>

Or more simply:-



<a href="http://www.google.com" onclick = "ff(this.href)">place</a>

<script type = "text/javascript">
function ff(which) {
alert (which);
}
</script>

Quizmaster: The TV show "The Merits of Ferrets" stars which kind of animal?
Contestant: I don't know.
Quizmaster: There's a clue, if you know where to look.
Contestant: I'm sorry, no.
Quizmaster (laughing): The answer is ferrets.
Contestant: Well, how was I supposed to know that?

pc131
09-30-2011, 11:17 AM
Philip M, thanks for your attention

But in my case link does not have onclick event, which is used by left click.

In my case it would be:



<a href="http://www.google.com">place</a>

<script type = "text/javascript">
function ff() {
var current_target=href;
alert(current_target);
}
</script>

But it doesn't work.

To clarify, let's imagine you right click on a link, context menu pops out, and you choose position "Copy shortcut" - I need THIS shortcut.

Thanks anyway

------------------------------------

I also tried:



function ff()
{
var rr=document.links[this].href;
alert(rr);
}


But it doesn't work, but it shows what I want to achieve. I want to get href of THIS (mouse is over it) link...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum