How does JS monitor page refresh and shutdown?

many methods have been tried on the Internet. Is there any complete code that can be posted? Thank you!

Mar.29,2021

//
window.onbeforeunload = function (event) {
    var event = event || window.event;
    if (event) {
        event.returnValue = "";
    }
    return '?';
}

at present, it seems that this method can only be used, as long as your page has been manipulated, such as text box editing. It will trigger a reminder, but the prompt can only be pre-set by the browser and you cannot change it. For example, 'are you sure you want to close the window' above is of no use.

Menu