how can I detect the user clicked on "open in new tab"?

I would like to execute javascript when a user navigates to a link.  I first tried this:

<a href="http://www.test.com" onclick="JsCall();">This is the Link</a>

which works fine, except if the user right-clicks and chooses "open in new window" or "open in new tab."  So then I tried this:

<a href="http://www.test.com" onclick="JsCall();" oncontextmenu="JsCall();">This is the Link</a>

which calls JsCall() for right-clicks now too.  The only problem is - what if, after right-clicking,  the user then does not choose "open in new window" or "open in new tab"?  They can choose something else from the right-click menu, or just change their mind altogether and close the menu.

Is there a way I can execute the JsCall() function only when they actually navigate to the link?

Thanks for your help!
maltomeal8Asked:
Who is Participating?
 
David S.Connect With a Mentor Commented:
As far as I know, what you want to do is not possible. Why do you want to be able to detect it anyway?
0
 
David H.H.LeeCommented:
Hi maltomeal8,
>>..Is there a way I can execute the JsCall() function only when they actually navigate to the link?
You can turn off right click function that link to  oncontextmenu event.
eg:
<a href="http://www.test.com" onclick="JsCall();" oncontextmenu="return false;">This is the Link</a>
0
 
Ryan ChongCommented:
try:

<a href="http://www.test.com" onclick="JsCall();return false;" oncontextmenu="JsCall();">This is the Link</a>

?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
maltomeal8Author Commented:
x_com:
I don't want to disable the right click menu - "open in new tab" is a nice feature that web users like.  I just want to know when they clicked on it.

ryancys:
Adding "return false;" to the onclick handler doesn't affect right-click at all since the onclick event is not fired when right-clicking.
0
 
maltomeal8Author Commented:
That's what I was afraid of... well, let me explain what I'm trying to do and maybe you'll have an idea of another way it can be achieved.

I am trying to track the user's clicks on links, much in the same way that Google tracks clicks on the results page of a search.  I am using Google Analytics for tracking, and calling their javascript function to track.  I want to track when a user navigates to a link in any way - left-click, right-click>"open in new tab", or right-click>"open in new window".

It seems like possibly it can't be done, but I would be surprised if Google does not track when people right-click>"open in new tab" on their search results.  

Thanks for your help.


0
 
Ryan ChongCommented:
>>but I would be surprised if Google does not track when people right-click>"open in new tab" on their search results.

It's browser issue, not the web page issue, so you probably can't trace that, what mostly you can know is the client browser and page referral, but can't know the user behaviour either open in new tab or open in new window.
0
 
maltomeal8Author Commented:
Does this site have a way I can offer, say 400 points to someone for providing a solution, but only 125 points to someone for convincing me that there is no solution? ;-)
0
 
David S.Commented:
If the answer is that what you want is not possible, then you must select that as the solution.
0
 
maltomeal8Author Commented:
Yes I know, but what I'm saying is that I'd be willing to give 400 points to someone who can come up with a solution, but only 125 points (the value it's at right now) if it's not possible.
0
 
Ryan ChongCommented:
It's not a problem of points here, sometimes you just can't get a solution you wish it can be done. Sometimes there is something technology can't do.
0
 
David S.Commented:
Oh, so you're saying that you'll increase the points if someone comes up with a solution.
0
 
maltomeal8Author Commented:
Yes, I would increase it to 400 if someone comes up with a solution.  If they don't in a few days, I'll just give the 125.
0
 
maltomeal8Author Commented:
too bad it can't be done, but thanks for the confirmation
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.