I have such a problem: I have link which on click opens ajaxFormDialog in modal dialog on top of the current page. But when I click middle button, it opens in new tab, and everything is not in modal window, but currently on new tab page and looks bad. So, my question would be, how it is possible to disable middle mouse button click for current link?
<a class="ajaxFormDialog" ...></a>
<script>
$(function (){
$('a.ajaxFormDialog').live("click", function(e) {
$.ajax({
type: "POST",
url: $("#formContent form").attr("action"),
data: $("#formContent form").serialize(),
success: function(data) {
//... do something
}
});
});
</script>
UPD I used your suggested
if(e.which == 2) {
e.preventDefault();
}
it maybe preventsDefault, but still opens new tab with that form. When I click with middle/mousewheel button on link it doesn`t even show me, that he entered this $(function (){ $('a.ajaxFormDialog').on("click", function(e) { ...
UPD2 I wrote such code:
$(function (){
$('a.ajaxFormDialog').live("click", function(e) {
console.log("Which button is clicked: " + e.which);
if(e.which == 2) {
e.preventDefault();
}
// rest of the code...
So when I click left mouse button, console shows me "Which button is clicked: 1", but when I click middle/mousewheel button it shows me nothing and still opens in new tab.