This code is useful when we want to apply a pop-up when a user is closing the tab. With the use of this code you can easily restrict the pop-up on page refresh or on navigating to other pages of the same website. Use this code in your header.php file :


<script type="text/javascript">

function PopIt() { return "write your custom message here"; }
function UnPopIt()  { /* nothing to return */ }

jQuery(document).ready(function() {
window.onbeforeunload = PopIt;
jQuery("a").click(function(){ window.onbeforeunload = UnPopIt; });
});

</script>

We can write our custom message to be shown in pop-up. Just type your message in place of “write your custom message here” written in above mentioned code.

Note : Custom message will not show in mozilla firefox browser.