473,378 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

JS onClick not executing when opening in new tab (Firefox)

Hello,

I have some onClick events in <a href...> elements, so they get called
when a user clicks on a link.
This works well, and looks like this:

<a onclick="onLinkClick(123);" href="......">foo</a>

Unfortunately, if a user opens the link in a new tab (e.g right
click->open in new tab), my onLinkClick function does NOT get called.
This happens with Firefox (various versions, including the latest one -
1.5.0.1).

Does anyone know if there is a way to work around that and catch even
the "open in new tab" clicks/events?

Thanks!

Mar 22 '06 #1
1 6241
OtisUsenet said on 22/03/2006 10:37 AM AEST:
Hello,

I have some onClick events in <a href...> elements, so they get called
when a user clicks on a link.
This works well, and looks like this:

<a onclick="onLinkClick(123);" href="......">foo</a>

Unfortunately, if a user opens the link in a new tab (e.g right
click->open in new tab), my onLinkClick function does NOT get called.
Nor will it get called from middle-click, or if the link is dragged to a
tab or the tab bar, or all the other ways of following a link without
using a standard click.

This happens with Firefox (various versions, including the latest one -
1.5.0.1).

Does anyone know if there is a way to work around that and catch even
the "open in new tab" clicks/events?


There is no way to monitor if your links are opened in a new tab or if
navigation has been initiated by a mouse event.

I think what you really seek is to know if a link on your page was used
to initiate navigation using any method - new tab or window, dragged,
clicked, tabbed to, and so on - but that is simply not possible.

You can monitor right mouse clicks, but the user may be right-clicking
to add a bookmark, view the link properties, or some other function.
You'd have to monitor all other mouse buttons too, since middle-button
opens links in a new tab by default (in Firefox) and other buttons may
be programmed to do it too - many mice have 5 or more buttons, plus
modifiers.

And what if the user drags the link to another tab/window? You won't
get a click event because the mouseup occurs outside the window.

You have similar problems with IE opening links in other windows using
right-click, modifiers, other buttons or dragged links.

And what about other pointing devices and UI interaction methods?

You need to re-think UI works.
--
Rob
Mar 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
10
by: Noozer | last post by:
Is it possible to detect where on a page the click occurred when the OnClick event of the BODY tag is fired? Thx
10
by: Eric-Sebastien Lachance | last post by:
Hey there, I decided to just create a 100% height and width div that filled the space over a background header image, and add an onclick event to redirect to the my index... Doesn't seem to work...
53
by: usenet | last post by:
See <ul> <li><a name="link1" onClick="alert(this.name);return false;" href="#">Link1</a></li> <li><a name="link2" href="javascript:alert(this);">Link2</a></li> <li>Item 3</li> </ul> ...
6
by: Nx | last post by:
i've got it all working nicely in firefox, but whenever i test it in IE none of the onclick events are triggered. i'm using an xsl to transform an rss feed into a photogallery. when i try to...
2
by: deergregoryd | last post by:
I've got some PHP and javascript working together to create a marginless image popup from another arbitrary image. This works perfectly in Firefox, but IE bombs and I'm not really knowledgable...
4
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of...
12
by: Andrew C | last post by:
Hi, folks. I've recently been doing a few simple tests and experiments. As a result, I've noticed that, in dealing with 'onclick', IE seems less able than Firefox to keep up with rapid clicking....
17
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/scripts/demo/this-alert.html http://www.frostjedi.com/terra/scripts/demo/this-alert2.html Why, when you click in the black box, do the alert boxes say different...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.