Hi @hi hi,
Unfortunately, you cannot disable refresh because:
- Keydown event (or any event) does not apply to the browser UI, which means if the focus is on the address bar, the keydown event would not be listened for. A user is able to hit ENTER key in the address bar.
- Either a prompt or refresh is expected in beforeunload event. And the only way to prevent refresh is a user selecting "Cancel". It always involves user interaction.
It is a by-design behavior in modern browsers. For more information, you can refer to this doc.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
Shijie Li