Disable single click action on Ctrl Click
I am facing a weird situation. On click i am binding an event which will call an AJAX function, but when i press Ctrl Click the default click action should be disabled. Is there any way i can achieve it.. please share any ideas on how to proceed further..
$('#demo1').click(function(e) {
if(e.ctrlKey == true) {
alert("con开发者_如何学运维trol click");
}
else {
alert("normal click");
$("#demo1").bind('select_node.jstree', function(event, data) {
var url = data.rslt.obj.children("a:eq(0)").attr("href");
$('.ui-layout-center').load(url);
});
}
});
Check e.ctrlKey
.
if ( e.ctrlKey || e.metaKey )
{
/* do your click thing (e.g. open-in-new-window) */
window.open( $(this).attr('data-url') );
return;
}
else
{
/* do your regular thing (e.g. go to another page) */
window.location.href = $(this).attr('data-url');
}
for the bind part, maybe e.preventDefault(); helps?
And: try a return false in the the above code, to prevent events from 'bubbling up'.
I am definitely not that familiar (only recently did I start in jquery) but would preventDefault and http://plugins.jquery.com/plugin-tags/ctrl-click help you at all?
精彩评论