Show alert message on browser back button but dont show alert on refresh
<p>I want to show a alert box when user click on browser back button. I found this but it shows on reload .. </p>

<pre><code>$(window).bind("beforeunload", function() {
    return "HI";
});
</code></pre>

<p>Edited :- </p>

<p>now I tried this one it shows alert box on back button but it also shows on refresh I dont want that.Code is :-</p>

<pre><code>var links = document.getElementsByTagName('a');
for (var i = 0; i &lt; links.length; i++)
{
    links[i].onclick = setGlobal;
}
function setGlobal()
 {
    window.linkClicked = true;
 }
window.onbeforeunload = function()
{
    if (typeof window.linkClicked == 'undefined' || !window.linkClicked)
    {
        return "Are you sure?"
    }
}
</code></pre>

<p>It shows the alert box even when I come to this page i dont want that I want if user click on back button if he is on this page.</p>

<p>Please Im new to this any help will be appreciated .Thanks in advance.</p>
