Java Script method to detect refresh event

JS function to detect refresh event

HTML

<p>Detecting the page refresh using Java Script </p>

JavaScript

function warning()
    {
       alert ('Detecting the page refresh using Java Script'); //you can put your code here.
    }
    window.onbeforeunload = warning();