Another implementation you can try:
<html>
<head>
<script type="text/javascript">
window.onbeforeunload = function() {
return "Did you save your stuff?"
}
</script>
</head>
<body>
</body>
</html>
Update
As mentioned in comment by @JohnnyFun "Starting with Firefox 44, Chrome 51, Opera 38 and Safari 9.1, generic message will be displayed for different browsers and cannot be customized".