离开我的网站显示带有消息的弹出框

When someone tries to leave my website I want to show them pop up message. I tried to use window.onbeforeunload function but it is not working.

<script language="JavaScript">
  window.onbeforeunload = confirmExit;
  function confirmExit(){
     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>

Hi Jonathan i want to show my custom messages in pop up. currently it shows default message - This page is asking you to confirm that you want to leave - data you have entered may not be save

2nd line of your core is buggy

It should be :

window.onbeforeunload=confirmExit();

Your line is missing the parenthesis, ().

Try this.

 $(window).bind('beforeunload', function() {        
        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?";
            });