JSFiddle - React, Tailwind, and code Playground

by andrewwhitaker

HTML

<a href="http://www.google.com">Google</a>
<input type="hidden" id="dirtyFlag" value="false" />

JavaScript

window.onbeforeunload = function() { 
    var el = document.getElementById("dirtyFlag");
    if (el.value === "true") {
        return 'You will lose all changes made since your last save';

    }
    else {
        return null;
    }
};