0

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);
                    }

                });
Community
  • 1
  • 1
Aamir Shahzad
  • 6,683
  • 8
  • 47
  • 70
  • You mean trigger an event depending on what item in the context menu you click? Don't think you can. – putvande Aug 13 '15 at 08:16
  • Why would you want such a behaviour? And basically, anyway, this is not possible – A. Wolff Aug 13 '15 at 08:33
  • As context menu is the natural thing to open if on right click without opening context menu it will be get rejected by my client. I have done some R&D on this I think I have to create a context menu to achieve that. However I will find some workaround and post as an answer. Thanks – Aamir Shahzad Aug 13 '15 at 10:35

0 Answers0