I'm trying to do a small survey on exit using onbeforeunload function.
Now the jquery script for that works good, but once the page refreshes or the back button is pressed the pop up shows again. I'm trying to disable it using jquery cookies plugin.
$.cookie('appeal'); // get cookie
$.cookie('appeal', 'the_value'); // set cookie
function PopIt()
{
if ($.cookie('appeal') == null)
{
$.cookie('appeal', 'CookiePlus', { expires: 7 });
$("a#trigger").trigger('click');
window.onbeforeunload = UnPopIt;
return "Before you leave:\nPlease take a few seconds to answer 2 questions\nso we can better assist you and others in the future. \nThanks!";
}
else {
}
}
function UnPopIt() { /* nothing to return */ }
$(document).ready(function() {
window.onbeforeunload = PopIt;
$("a#trigger").fancybox({
'hideOnContentClick': false,
'showCloseButton': true
});
$("a[id!=trigger]").click(function(){ window.onbeforeunload = UnPopIt; });
});