I have a page which have a next and previous button. when user click on next/back button, a new page will open. when ever i close the window i get the alert message. But the same message came when i click on next/previous button. I want alert message only when some one close the window.

I am using following code.

<script type="text/javascript" for="window" event="onunload">
alert("The onunload event fired for the window object.");