java script+onbefore unload
<p>i m creating a web application, after login user navigates to home page where i have a <strong>navbar</strong>(Links to pages/url).<strong>Navbar</strong> is like this
<strong>Home</strong>-Nvigates to home page
<strong>Profile</strong>-Navigates to profile page
<strong>Chat</strong>-navigates to chat page when user clicks on chat link .
I want that when  user closes the browser window ,accidentally or manually he should get an alert for that i have used onbeforeunload function like this</p>

<pre><code> &lt;script language="JavaScript"&gt;
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
  }
&lt;/script&gt;
</code></pre>

<p>Now when i m closing the browser on chat page i m getting following alert "You have attempted to leave this page." that is working fine,but now the main problem is that when i m clicking on other links like 
<strong>Profile</strong> or <strong>Home</strong> this function is called and me geting this alert even though i have implemented this code in chat.jsp .Even i m <strong>refreshing</strong> this page i m getting this alert mentioned above which i should get only when i closes widow of chat.jsp page rather than other pages or Refresh.Plese help</p>
