The function works in IE mode, but not in other browsers.
This is absolutely normal. Other browsers simply do not allow you to warn about this feature.
Verify that the fiddle is in Chrome:

Sorry, you should forget about the alert in the onbeforeunload handler. The only thing you should do in this handler is to return the result of the string:
window.onbeforeunload = function (e) { var y = window.event.clientY;// e.pageY || e.clientY; if (y < 0) { return 'Window closed'; } else { return 'Window refreshed'; } };
The responsibility of the browser is to decide how to display this information to the user, and not to you, by reporting this explicitly.
source share