1

I have tried the following code to suppress the default right click on a Leaflet popup:

$('.leaflet-popup-content-wrapper').bind('contextmenu', function(e) { return false; });

This technique works fine on all other classes but not in this instance.

Any ideas?

Peter
  • 11
  • 4

1 Answers1

0

There is no such thing as "suppresing" an event. You can stop propagation of an event, and prevent the default action of an event, but supressing an event is not a thing.

Do read:

http://leafletjs.com/reference-1.0.3.html#domevent-stoppropagation

http://leafletjs.com/reference-1.0.3.html#domevent-preventdefault

http://leafletjs.com/reference-1.0.3.html#domevent-stop

https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation

https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault

event.preventDefault() vs. return false

Do you want to stop the event from bubbling? Do you want to prevent the browser from displaying the right-click menu? Both?

Also note that jQuery events are not DOM events, and furthermore, Leaflet events are not DOM events. Stopping a jQuery/Leaflet event might not stop the underlying DOM event under some circumstances. Using Vanilla JS or some super-simple wrapper as L.DomEvent.on() helps to regain control in these cases.

IvanSanchez
  • 18,272
  • 3
  • 30
  • 45