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

O

OtisUsenet

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!
 
R

RobG

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top