Im just a newbie in Javascript but I have some serious problem which I searched for many hours on different sources, so I decided to post this question.How do you stall/pause a javascript before an asp.net page is refreshed or closed?Here is the code:\[code\]<script type="text/javascript"> window.onbeforeunload = confirmExit; function confirmExit() { var connection = new Ext.data.Connection({ defaultHeaders: { 'Content-Type': 'application/json' } }); connection.request({ url: 'services/vault/deletewfinstace/' }); refresh(); //alert("Helloo"); } function refresh() { setTimeout(function () { window.location.reload() }, 6000); }</script>\[/code\]In this code I have called a javascript function on the event: window.onbeforeunload, and tried to put a setTimeout() after the function has done its work, but still page refreshes or closes without completing the contents of the function properly. The contents inside the function will execute successfully when I use alert() at the end of the function, but it is somewhat annoying to the user. Please help. Thank you.