I have a leaflet map, I would like to change closeOnClick property of a popup after it is opened. I have tried this code but it doesn't work.
// at build
var mapPopupOptions = {maxWidth:600,minWidth:300};
var popup = new L.popup(mapPopupOptions).setContent("hello world");
// elsewhere after popup is open
popup.options.closeOnClick = false;
For reference: http://leafletjs.com/reference.html#popup
I know this question is very old, but I have just found a solution.
It does not matter whether you are getting the popup object from the marker using getPopup() or directly from a previous declaration.
For some reasons, the update() method does not work properly since it only updates the popup's aspect (className, offset, minWidth...) but not options' attributes relative to the popup's behavior.
Leaflet's popup's behavior (such as closeOnClick or autoClose) can be updated by re-initializing the popup's layout with the _initLayout() method.
For example in this case:
// Once the popup has been created and/or opened
popup.options.closeOnClick = false;
popup._initLayout();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With