Currently, I'm using this code:-
window.addEventListener('beforeunload', (event) => {
event.preventDefault();
event.returnValue = '';
});

But it does not appear what I want. What else JavaScript code available?

Currently, I'm using this code:-
window.addEventListener('beforeunload', (event) => {
event.preventDefault();
event.returnValue = '';
});

But it does not appear what I want. What else JavaScript code available?

window.addEventListener('beforeunload', (event) => {
event.preventDefault();
event.returnValue = '';
});
Will not do anything as preventDefault() cannot stop page from loading. Instead you should use return false;. Also with that nothing else can come in the function and the user can just choose whether to stay or leave. So your code will become:
window.addEventListener('beforeunload', (event) => {
return false;
});
If you add anything else in the function your code will not work.