detecting reload vs. close of browser

JavaScript

window.onbeforeunload = function() {
        return "Dude, are you sure you want to refresh? Think of the kittens!";
}