禁用新标签中的打开或控制/中间点击某些链接?

时间:2011-10-06 14:52:26

标签: ajax

如果用户尝试这样做,我想停止在新标签页中打开某些链接(我认为Gmail会以某种方式执行此操作)。这是为了阻止人们自己加载由ajax加载的页面。

2 个答案:

答案 0 :(得分:4)

$('a').click(function(event){
    event.preventDefault();
    window.location = $(this).attr('href');
});

答案 1 :(得分:3)

$('.no_new_tab').mousedown(function(e){
    if(e.which==2) { // 2 is middle click
        //console.log('new tab attemp');
        e.preventDefault();
        window.location = $(this).attr('href');
    }
});
相关问题