Home > OS >  Is it possible to prevent a user from saving a webpage with CTRL S? (asking for a friend)
Is it possible to prevent a user from saving a webpage with CTRL S? (asking for a friend)

Time:12-20

Is it possible to stop the Save as website.html from appearing when you press CTRL S in either HTML, Javascript, or CSS?

CodePudding user response:

 $(document).on("keydown", function(e) { 
    if ( e.ctrlKey && ( e.which === 83 ) ) {
        e.preventDefault();
    }
    });

CodePudding user response:

You can prevent this by using Event.preventDefault()

document.addEventListener('keydown', function(event) {
  if (event.ctrlKey && event.key === 's') {
    event.preventDefault();
    alert('Save Event!');
  }
});

More Details:
https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault
  • Related