Differentiate browser refresh and browser close
问题 I want to set a cookie when a visitor on the page closes the browser. I used onbeforeunload method like this <script language="JavaScript" type="text/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> followed this link But found out that even refresh of page or