Here’s what I made.
Thanks for the prompt @codekraft
$('input').on('keydown, keyup', function () {
window.addEventListener('beforeunload', (event) => {
event.preventDefault();
// Google Chrome requires returnValue to be set.
event.returnValue = '';
});
});