I have the following:
<script>
$(window).on('beforeunload', function() {
return 'Are you sure you want to exit?';
});
</script>
I am interested to have this fire when the user leaves my site.
However, I do not want this to fire when the user leaves my site pressing the "I agree" button.
I have a few "I agree" buttons throughout my page. What's an elegant way to achieve this?
答案 0 :(得分:0)
One possible solution is to unbind that event handler when the "I agree" button is pressed, you can give them a common class in order to trigger this event when any of them are pressed.
<script>
$(window).on('beforeunload', function() {
return 'Are you sure you want to exit?';
});
$('.iagreebtn').on('click', function() {
$(window).unbind('beforeunload');
}
</script>