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