As you know the code
window.onbeforeunload = function(){
return 'my message';
};
runs the alert before user leaves a page OR reloads current page OR jumps to another page of the same website. Is there some solution only for the case when the user leaves the website (domain) by closing the tab of browser?