I have a following code (Code Snippet 01) to open a link. Note that I can't modify href
can only use window.open or any jquery method to open the link.
For that I have used following code
$('#element').mousedown(function(event) {
switch (event.which) {
case 1:
alert('Left Mouse button pressed.');
break;
case 2:
alert('Middle Mouse button pressed.');
break;
case 3:
alert('Right Mouse button pressed.');
break;
default:
alert('You have a strange Mouse!');
}
});
From here
It works for right click and middle but on the left click instead of opening context menu it directly opens the link. Is there any way we can handle that? It open the context menu and and clicking on new tab or new window open our link?
Code Snippet 01
var $pdflink = jQuery.noConflict();
$pdflink(document).ready(function(){
$pdflink(".PRLink").click(function(e){
e.preventDefault();
var pdf = $pdflink(this).parents(".getpdflink").find(".pdflinkforlink").attr("href");
var html = $pdflink(this).parents(".getpdflink").find(".htmllink").attr("href");
if(pdf) {
window.open (
pdf, '_blank'
);
//$pdflink(this).find(".PRLink").attr("href", pdf);
} else {
window.open (
html, '_blank'
);
//$pdflink(this).find(".PRLink").attr("href", html);
}
});