In a recent project, I implemented an event that triggers an alert box when a user attempts to close the tab or window, giving them the option to stay or leave. While this functionality is working correctly, my goal is to also make an invisible div element on the page visible when the alert box appears. Is there a way to achieve this without compromising the existing setup? I am aware that only one value can be returned in the current configuration. Any suggestions on how I can make the div visible before triggering the return action would be greatly appreciated.
Code:
$(window).bind('click', function(event) {
if(event.target.href) $(window).unbind('beforeunload');
});
$(window).bind('beforeunload', function(event) {
$('offerWindow').css("visibility", "visible");
return 'Press "Stay on Page" and get a special offer!';
});