JSFiddle - React, Tailwind, and code Playground

HTML

<h1 id="test">Hello</h1>

JavaScript

function doSomething(){
    //do some stuff here. eg:
    document.getElementById("test").innerHTML="Goodbye!";
}
function showADialog(e){
    var confirmationMessage = 'Your message here';
    //some of the older browsers require you to set the return value of the event
    (e || window.event).returnValue = confirmationMessage;     // Gecko and Trident
    return confirmationMessage;                                // Gecko and WebKit
}
window.addEventListener("beforeunload", function (e) {
    // to do something (Remember, redirects or alerts are blocked here by most browsers):
    doSomething();    
    // to show a dialog (uncomment to test):
    return showADialog(e);  
});