如何使用jquery在新选项卡或窗口中捕获打开的链接? [英] how to capture open link in new tab or window using jquery?

查看:63
本文介绍了如何使用jquery在新选项卡或窗口中捕获打开的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用jQuery捕获在新窗口/选项卡中打开右键并在新窗口/选项卡事件中打开鼠标滚轮?

更新1

这就是我需要它的原因。我有使用分页类的codeigniter应用程序。我用这个类来显示一个网格。分页链接已与使用AJAX加载容器div中的下一页的方法绑定。现在有人可以右键单击并在新标签/窗口中打开我不想要的下一页。恕我直言,解决这个问题的唯一方法是在新窗口/标签事件中打开(右键单击或鼠标滚轮按钮点击)陷阱。

更新2

我刚刚意识到我的所有AJAX请求都由一个CI控制器提供服务,它实际上充当其他类/库的代理。在这个控制器中,我可以查看请求,如果它不是AJAX请求,我可以将用户重定向到另一个页面。

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.

推荐答案

解决方案解决方案是替换所有适用的< a> 带按钮的元素,其中(显然)按钮会调用执行相应导航的JavaScript。

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

如果您真的很热衷,可以使用CSS来使按钮看起来像< a> 元素,但我不推荐它,因为它会混淆那些可能会尝试将它们视为标准链接并右键或中间点击它们的用户。

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.

(您甚至可以让没有启用JavaScript的用户使用它,例如,使每个按钮成为自己的小形式的提交按钮。)

(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.)

这篇关于如何使用jquery在新选项卡或窗口中捕获打开的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆