<div id="pain" class="modal"> <div class="popup"> <div class="popup-content"> <p>you have not saved your data , Would you like to save it before leaving ?</p> <button id="cancel">Cancel</button> <button id="leave">Leave</button> </div> </div> </div>
var popup_open = false; var popupElement = document.getElementById('pain'); window.addEventListener("beforeunload", function (event) { event.returnValue = false; event.preventDefault(); popupElement.style.display = 'block'; popup_open = true; });
Window: beforeunload event - Web APIs | MDN[^]: You should note that modern implementations: ... Only show a generic browser-specified string in the displayed dialog. This cannot be controlled by the webpage code.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)