This is a small technique to stop opening new tab from a hyperlink using jquery. It will stop to open right click – > open link in new tab and ctrl + click over the link.
Simple Example (Prevent to open new new tab by right click and ctrl + click)
js code
$(document).ready(function(){
$(".my").bind("contextmenu", function(e){
e.preventDefault(); // Stop right click on link
return false;
});
var control = false;
$(document).on("keyup keydown", function(e) {
control = e.ctrlKey;
});
$(".my").on("click", function(e) {
if (control) {
return false; // Stop ctrl + click on link
}
});
});
HTML Code
Right click on me (Pls also try ctrl + click)= I will not open new tab