I have a jquery script that attaches a click event to every link, running an action when the link is clicked. This has been working great, but I just got some betatester feedback that's foiling me.
我有一个jquery脚本,它将click事件附加到每个链接,在单击链接时运行一个动作。这一直很有效,但我得到了一些反对意见,这些反馈正在挫败我。
The user was right-clicking on the link and opening it in a new tab. When she did this, jquery didn't trap the click. BAD USER. I reproduced this with cmd-click as well.
用户右键单击链接并在新选项卡中打开它。当她这样做时,jquery没有捕获点击。坏用户。我也用cmd-click再现了这个。
Is there a way to trap these gestures, or this an inherent limitation?
有没有办法捕捉这些手势,或者这是一个固有的限制?
3 个解决方案
#1
So you want to capture every click? Event the right or middle one? Shouldn't the mousedown event do just that?
所以你想捕获每一次点击?事件正确还是中间? mouownown事件不应该这样做吗?
Of course, she could right click a link just to "Copy Link Location"...
当然,她可以右键单击“复制链接位置”链接...
#2
See if you can somehow make use of jQuery rightclick plugin:
看看你是否可以以某种方式使用jQuery rightclick插件:
http://abeautifulsite.net/notebook/68
Usage:
$(document).ready( function() {
// Capture right click
$("#selector").rightClick( function(e) {
// Do something
});
// Capture right mouse down
$("#selector").rightMouseDown( function(e) {
// Do something
});
// Capture right mouseup
$("#selector").rightMouseUp( function(e) {
// Do something
});
// Disable context menu on an element
$("#selector").noContext();
});
As for the cmd-clickie bit, I'm really not sure. In case it's helpful, here's the jQuery hotkeys plugin:
至于cmd-clickie位,我真的不确定。如果它有用,这里是jQuery热键插件:
http://www.webappers.com/2008/07/31/bind-a-hot-key-combination-with-jquery-hotkeys/
#3
I've seen jquery.rightclick.js code in firebug. There are modifiers with the mousedown and mouseup event like:
我在firebug中看过jquery.rightclick.js代码。有mousedown和mouseup事件的修饰符,如:
altKey ctrlKey
so you can use these two modifiers:
所以你可以使用这两个修饰符:
if(evt.altKey || evt.ctrKey)
if(evt.altKey || evt.ctrKey)
in jquery.rightclick.js
#1
So you want to capture every click? Event the right or middle one? Shouldn't the mousedown event do just that?
所以你想捕获每一次点击?事件正确还是中间? mouownown事件不应该这样做吗?
Of course, she could right click a link just to "Copy Link Location"...
当然,她可以右键单击“复制链接位置”链接...
#2
See if you can somehow make use of jQuery rightclick plugin:
看看你是否可以以某种方式使用jQuery rightclick插件:
http://abeautifulsite.net/notebook/68
Usage:
$(document).ready( function() {
// Capture right click
$("#selector").rightClick( function(e) {
// Do something
});
// Capture right mouse down
$("#selector").rightMouseDown( function(e) {
// Do something
});
// Capture right mouseup
$("#selector").rightMouseUp( function(e) {
// Do something
});
// Disable context menu on an element
$("#selector").noContext();
});
As for the cmd-clickie bit, I'm really not sure. In case it's helpful, here's the jQuery hotkeys plugin:
至于cmd-clickie位,我真的不确定。如果它有用,这里是jQuery热键插件:
http://www.webappers.com/2008/07/31/bind-a-hot-key-combination-with-jquery-hotkeys/
#3
I've seen jquery.rightclick.js code in firebug. There are modifiers with the mousedown and mouseup event like:
我在firebug中看过jquery.rightclick.js代码。有mousedown和mouseup事件的修饰符,如:
altKey ctrlKey
so you can use these two modifiers:
所以你可以使用这两个修饰符:
if(evt.altKey || evt.ctrKey)
if(evt.altKey || evt.ctrKey)
in jquery.rightclick.js