Modal disable "close on esc"

Hey there,

I have a project where I need to show a modal and the user needs to agree to that modal to visit the page. Something like “i am over 18 years” or such stuff (don’t know if it is really needed by law, but the customer wants it, so … )

The modal has an option to prevent closing when the backdrop is clicked. But it is not possible yet to disable the close on esc key feature.

I’ve tried to work around with mutation observers and overwriting the key event, but that wasn’t really good/successful.

It would be cool if a toggle could be implemented to switch that option on/off!



1 Like

I thought this is an option, but apparently isn’t.

For the use cases you mentioned, the options which are already available, such as appear and show again, are quite useful. This functionality probably replaces another dedicated plugin.
Disabling close on ESC would be a good (and for this use case required) addition.

If so, this is most likely no complete solution, as it might be required to track actions like with a cookie banner; but of course always depends on the local laws.

Hello @Wolfgang,

Thanks bringing this up.
Definitely something that needs to be added in the coming updates.


Hey @Marius , sorry I’ve somehow overread your answer.

Yes I did something very simple, which isn’t probably the best solution, but it was a quick fix and I didn’t dig that deep into all the settings yet. What I did is using the “sessionstorage” to create a Boolean, so the Modal can show up on every first page request, but doesn’t appear again on when the user navigates between pages:

window.addEventListener("DOMContentLoaded", () => {
  const modalAcceptance = sessionStorage.getItem("acceptModal");

  if (!modalAcceptance) return;

  const modal = document.querySelector("#modal-c20dd1e");


There’s probably a setting for it! :smiley:

Yes probably, I’m pretty sure that in this case (it’s some kind of a health company with a hint they want to show on page load) it is not needed by law, that’s why it doesn’t have to be perfect, but the prevent close on esc key feature would be cool to have anyway, i guess! :wink:

It is, and everything is self explanatory - no digging required :+1:
But thanks for sharing your approach here, could be used as a blueprint for more granular requirements.
But I think 99.99% of the use cases are covered anyway. It’s really powerful, you should check it out.

This has been added with version

Works as intended on my side :v:

1 Like