elabuwa Posted October 28, 2011 Share Posted October 28, 2011 Hi Guys, seen some pages who give alerts or Warnings mentioning that i'm moving away from my webpage. Best example is hotmail when you are on the compose mail screen and when click another link it is asking for confirmation. Can you one please shed some light on how to do this. Your help is greatly appreciated. Cheers Dileep Quote Link to comment https://forums.phpfreaks.com/topic/249970-alert-when-moving-out-of-web-page/ Share on other sites More sharing options...
AyKay47 Posted October 28, 2011 Share Posted October 28, 2011 there is no easy solution to this to my knowledge.. also can be pretty annoying to the people viewing your site so I really don't recommend it.. but if you have a good reason for doing it then you might want to look at the onunload event.. also to point you in the right direction.. http://stackoverflow.com/questions/2365994/display-a-warning-when-leaving-the-site-not-just-the-page Quote Link to comment https://forums.phpfreaks.com/topic/249970-alert-when-moving-out-of-web-page/#findComment-1282970 Share on other sites More sharing options...
nogray Posted October 28, 2011 Share Posted October 28, 2011 You can do window.onbeforeunload = function(){ return 'are you sure you want to leave?'; } Quote Link to comment https://forums.phpfreaks.com/topic/249970-alert-when-moving-out-of-web-page/#findComment-1283125 Share on other sites More sharing options...
AyKay47 Posted October 28, 2011 Share Posted October 28, 2011 You can do window.onbeforeunload = function(){ return 'are you sure you want to leave?'; } this will lead to undesired results, ex. clicking an anchor that links to an internal page will trigger this.. since it looks for the DOM being unloaded only Quote Link to comment https://forums.phpfreaks.com/topic/249970-alert-when-moving-out-of-web-page/#findComment-1283158 Share on other sites More sharing options...
Zane Posted October 28, 2011 Share Posted October 28, 2011 this will lead to undesired results, ex. clicking an anchor that links to an internal page will trigger this.. since it looks for the DOM being unloaded only OP Best example is hotmail when you are on the compose mail screen and when click another link it is asking for confirmation. Dileep Seems to me that this is exactly what the OP wants. Quote Link to comment https://forums.phpfreaks.com/topic/249970-alert-when-moving-out-of-web-page/#findComment-1283160 Share on other sites More sharing options...
AyKay47 Posted October 28, 2011 Share Posted October 28, 2011 possibly.. I gave some suggestions for this already.. however I advise against it.. that's all I'm saying Quote Link to comment https://forums.phpfreaks.com/topic/249970-alert-when-moving-out-of-web-page/#findComment-1283163 Share on other sites More sharing options...
Network_ninja Posted October 29, 2011 Share Posted October 29, 2011 Just a wild guess. Is it a registration form or adding contents? and you would like to give warning to the user that if he/she navigates away from page the data will not be save? then you can use what nogray provided. and for undesired result you could add checking if the content has a content and fire the javascript: I'm talking about like this: <html> <head> <title>Untitled Document</title> <script type="text/javascript"> window.onbeforeunload = function(){ var txt = document.getElementById("content").value; if(txt != '') { return 'are you sure you want to leave?'; } } </script> </head> <body> Type content here: <input type="text" name="content" id="content"> </body> </html> Just a suggestion and wild guess. cheers! Quote Link to comment https://forums.phpfreaks.com/topic/249970-alert-when-moving-out-of-web-page/#findComment-1283176 Share on other sites More sharing options...
elabuwa Posted October 29, 2011 Author Share Posted October 29, 2011 thank you guys. Will check your suggestions and let u know Quote Link to comment https://forums.phpfreaks.com/topic/249970-alert-when-moving-out-of-web-page/#findComment-1283195 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.