Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to capture open link in new tab or window using jquery?

Is it possible to capture the right click open in new window/tab or mouse wheel open in new window/tab event using jQuery?
UPDATE 1
Here is why I need it. I have codeigniter application which uses pagination class. I use this class to display a grid. The pagination links have been bind with a method that uses AJAX to load the next page in a container div. Now some one can right click and open the next page in new tab/window which I don't want. IMHO, the only way to handle this is to some how trap the (right click or mouse wheel button click) open in new window/tab event.
UPDATE 2
I just realised all my AJAX requests are being served by one CI controller which actually acts as a proxy to other classes/libs. In this controller I can look at the request and if it isn't an AJAX request I can redirect the user to another page.

like image 507
Kumar Avatar asked Nov 14 '22 15:11

Kumar


1 Answers

A workaround solution is to replace all applicable <a> elements with buttons, where (obviously) the buttons would call JavaScript that does the appropriate navigation.

If you're really keen you can apply CSS to make the buttons look like <a> elements, though I don't recommend it because it confuses users who might try to treat them as standard links and right- or middle-click them.

(You could even get it to work for users that don't have JavaScript enabled by, e.g., making each button a submit button in its own little form.)

like image 80
nnnnnn Avatar answered Jan 12 '23 02:01

nnnnnn