Good day! Please give me sample code on how to do popup message when someone leaves a website. Thanks Kind Regards, Matt
Matt - give this a try: <script type = "text/javascript"> var needToConfirm = true; window.onbeforeunload = confirmExit; function confirmExit() { if (needToConfirm) { return "You have attempted to refresh or leave this page. If you have made any changes to the fields without clicking the Save button,your changes will be lost. Are you sure you want to exit this page?"; } } </script> <input type="Submit" value="Save" onclick="needToConfirm = false;" />
This will generate a pop up message/alert before the page fully loads..... <script language="Javascript"> alert ("HERE WRITE YOUR TEXT") </script>
Pretty useless piece of code, no offense, terrypasencio. Check this instead, a clean method: staying_in_site = false; Event.observe(document.body, 'click', function(event) { if (Event.element(event).tagName == 'A') { staying_in_site = true; } }); window.onunload = popup; function popup() { if(staying_in_site) { return; } alert('I see you are leaving the site'); } Code (markup):
Hello Clive, Heartly thanks to you for this suggestion..ya its really a clean method then what i recommended...
Will these codes work on Blogger as well If I insert them in the HTML/Javascript Widget or does it need to be inserted in the template?
Not to worry, all good Yes, and that will popup the message on every link click, even if it's an internal link. Site visitors will dump the website faster than one can imagine.
Is that another IE bug? If you use target="_blank", the JS doesn't fire in sane browsers. @SOLOWPOET: It needs to be on the actual page. If you can get your template to include it on the page, it'll work.