Edit: This question is different as I am asking for a solution in 2017 browser. The other question relates to browsers years ago. Also it gives no solution. There must be some sort of solution, and that is what I am asking for.
I have added an event listener:
addEventListener("beforeunload", MyBeforeUnload, false);
I have my function:
function MyBeforeUnload() {
if(!g_IsSaved) {
return "You have not saved your data. If you leave this page without saving, your data will be lost.";
}else {
// Do not return anything if ok to leave
}
}
This triggers and displays a warning message in IE.
It triggers the function and correctly returns the string, BUT does not fire the warning message in Chrome, Edge or Firefox when closing the browser with the [x] button in the top right of the browser.
Is it possible to get this working cross-browser in 2017?