I tried using windows.onbeforeUnload(). Using this function when I click try to click on any url on the page it gives me alert also if I try to reload the browser it gives me alert and while closing the browser it gives me alert. My requirement is that I want alert to be displayed only upon browser close.