I have this code to prompt user when leaving page <script language="JavaScript"> var needToConfirm = true; window.onbeforeunload = confirmExit; function confirmExit() { if (needToConfirm) return "You have attempted to 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> But i need some modification that user should not prompt when navigate to internal pages. User should prompt in case navigate away from my site to external site link.
Try such <a href="http://www.externallink.com" onclick="alert('Please do not run from my website'); return false;">Download</a> href="the external link" onclick="here goes the JS; return false;" return false for the disabling of clicking. So they can one "Right Click & Save of OPEN in new window" its easy
You could just set needtoconfirm to false whenever an internal link or button is clicked. Although surely there would be a much more efficient way to achieve this, rather then adding code to every internal link or button.
here is a better solution: <a href="http://www.google.com">Google</a> <a href="internal1.html">Internal link 1</a> <a href="internal2.html">Internal link 2</a> <script type="text/javascript"> var needToConfirm = true; window.onbeforeunload = confirmExit; function confirmExit() { if (needToConfirm) return "You have attempted to 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?"; } var links = document.getElementsByTagName("a"); for(i=0;i<links.length;i++) { if(links[i].getAttribute("href").search("http://")==-1){ links[i].onclick=function() { needToConfirm = false; return true; } } } </script> Code (markup): This will automatically stop internal links from displaying the alert.