Enable right click ONLY in an input

0

I have disabled the right click on the whole page, but I need it to be enabled in a single input to paste text, since javascript does not allow to take the contents of the clipboard.

I have it disabled like this:

     $(document).bind("contextmenu",function(e){
        return false;
     });

And I try to enable the right click on the element "#insertlink" (which is an input) or on "#pegarlink" (which is a div) in the following way:

  $("#pegarlink").bind("contextmenu", function(e){
        return true;
  });

But it does not work for me, probably because the previous rule is more strict, how can I enable the right menu on a single input?

Thanks

    
asked by Fabián Moreno 09.06.2018 в 16:54
source

1 answer

1

You can use the goal of the event that jQuery passes to the function, and thus determine the element on which it has the event has been activated.

$(document).on('contextmenu',function(e){

    if ( e.target.id == 'pegarlink' ) {
        return true;
    }

    return false;
});

Another consideration is that the method .bind() is considered obsolete, it is recommended to use .on() instead.

    
answered by 10.06.2018 в 09:35