I'd like to stop certain links from opening in a new tab if the users tries to do so (I think Gmail does this somehow). It is to stop people loading pages meant to be loaded by ajax on their own.
如果用户试图这样做,我想停止在新标签页中打开某些链接(我认为Gmail会以某种方式执行此操作)。这是为了阻止人们自己加载由ajax加载的页面。
2 个解决方案
#1
4
$('a').click(function(event){
event.preventDefault();
window.location = $(this).attr('href');
});
#2
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');
}
});
#1
4
$('a').click(function(event){
event.preventDefault();
window.location = $(this).attr('href');
});
#2
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');
}
});