vinpkl Posted November 22, 2008 Share Posted November 22, 2008 hi all i am facing trouble in calling function on window unload. <script language="javascript"> window.onunload = function() { alert("bye"); } </script> i want to call this script only when the user closed the browser tab. but i m getting this alert on every refresh and when i leave this page and click another buton link page. means i have this script on my index page and when i leave it go to contact us page then also i get this alert and everytime i refresh the page. how can i get this alert only when i close the browser tab. vineet Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 22, 2008 Share Posted November 22, 2008 Try window.onclose() instead of window.onunload(). Quote Link to comment Share on other sites More sharing options...
vinpkl Posted November 23, 2008 Author Share Posted November 23, 2008 hi porjectfear have u tried it. if yes then plz tell me. i m trying it in IE7 and Firefox 3 and its not working on both browsers. Not getting any alert on refresh and not getting any alert on closing window. <script language="javascript"> window.onclose = function() { alert("do you want to exit"); } </script> vineet Quote Link to comment Share on other sites More sharing options...
dropfaith Posted November 23, 2008 Share Posted November 23, 2008 <script language="javascript"> var displayPrompt=true; </script> <script language="JavaScript" event="onbeforeunload()" for="window"> if (displayPrompt){ event.returnValue = "If you leave now, your answers will be lost. If you intend to return to the survey,\npelease use the pause button at the end of each page."; } </script> then in all your links... that you dont want this to pop up on use this below?? <a href="LINKSURL" onclick="displayPrompt=false">link</a> Quote Link to comment Share on other sites More sharing options...
vinpkl Posted November 23, 2008 Author Share Posted November 23, 2008 hi drop faith this code displays alert on every refresh. what can we do for it. is there any solution. can ajax or anyother language help us. i m using it in IE7. <script language="javascript"> var displayPrompt=true; </script> <script language="JavaScript" event="onbeforeunload()" for="window"> if (displayPrompt){ event.returnValue = "If you leave now, your answers will be lost. If you intend to return to the survey,\npelease use the pause button at the end of each page."; } </script> THANKS VINEET Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.