?
Solved

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

Posted on 2009-02-23
13
Medium Priority
?
788 Views
Last Modified: 2012-05-06
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!
0
Comment
Question by:maltomeal8
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 23718018
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
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 23718203
try:

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

?
0
 

Author Comment

by:maltomeal8
ID: 23719263
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 43

Accepted Solution

by:
David S. earned 500 total points
ID: 23719354
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
 

Author Comment

by:maltomeal8
ID: 23719519
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
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 23722331
>>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
 

Author Comment

by:maltomeal8
ID: 23739934
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
 
LVL 43

Expert Comment

by:David S.
ID: 23740255
If the answer is that what you want is not possible, then you must select that as the solution.
0
 

Author Comment

by:maltomeal8
ID: 23741132
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
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 23741231
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
 
LVL 43

Expert Comment

by:David S.
ID: 23741752
Oh, so you're saying that you'll increase the points if someone comes up with a solution.
0
 

Author Comment

by:maltomeal8
ID: 23747428
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
 

Author Closing Comment

by:maltomeal8
ID: 31550432
too bad it can't be done, but thanks for the confirmation
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question