开发者

Javascript or jquery - is there a way to dismantle an anchor tag

开发者 https://www.devze.com 2023-02-15 20:46 出处:网络
so that it\'ll only respond to a right mouse click? If the user left clicks on the link I wa开发者_运维问答nt to just hide it. I can capture right or left mouse clicks through:

so that it'll only respond to a right mouse click? If the user left clicks on the link I wa开发者_运维问答nt to just hide it. I can capture right or left mouse clicks through:

$(".hideDataFileLink").live('mousedown', function(e) { 
    if (e.which == 3) { 
        $(this).slideUp('fast');
    } 
});

where 1 = left, 2 = middle, 3 = right. In the end, either click hides the link after the click but this is for downloading a text dump from a database and if you left click on the link you leave the page and load the text in your browser. I don't want that option to happen.

Thanks


Just add return false or e.preventDefault() to stop the browser following the link:

$(".hideDataFileLink").live('mousedown', function(e) { 
    e.preventDefault();
    if (e.which == 3) { 
        $(this).slideUp('fast');
    } 
    // or return false here, but that will also stop the event from
    // bubbling up to the parent which is needed in some cases
});


Just include something like this in your function to return false if the user clicks the right mouse button, and leave the rest alone.

if (e.which == 1) { 
  return false;
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消