D
D
Dmitry Sch2021-10-01 15:34:57
JavaScript
Dmitry Sch, 2021-10-01 15:34:57

How to cancel the standard action on ESC in Safari?

When using Safari in full screen mode and pressing the "Esc" key, the full screen mode is first exited and only when pressed again, the standard keyup event fires. How can this be overcome?
For an example on the modal https://codepen.io/DmitrySheklein/pen/VwWNYoj

Auto.ru somehow managed to do this (if you open and close the carousel of a car photo), but I did not find a fix for this problem in the code.
https://auto.ru/review/cars/toyota/verso/8507941/8...

macOS Big Sur 11.6

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergei Nazarenko, 2021-10-02
@DmitrySheklein

document.onkeydown = function (evt) {
    if (evt.keyCode == 27) evt.preventDefault();
  document.querySelector('.modal').classList.remove('show')
}

or
const handleEscClose = evt => {
  if (evt.keyCode == 27) {
    evt.preventDefault();
    document.querySelector('.modal').classList.remove('show')
  }
};
document.addEventListener('keydown', handleEscClose);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question