Add onbeforeunload event to page

Permalink
I want to add an onbeforeunload event to a page. It is a form page with multiple sections and I am finding that people are leaving the page without submitting the form. I want to verify that they really want to leave the page. Is that possible in Concrete5?

 
jero replied on at Permalink Reply
jero
Yes, I'd say so. It sounds like you would need to be using jQurey or javascript for this, so you can use an HTML block and paste in your javascript code.
Annalyzer replied on at Permalink Reply
That's what I thought, but it doesn't seem to recognize the event onbeforeunload.
jero replied on at Permalink Reply
jero
This is really more of a javascript issue than concrete5, but I would suggest that maybe you might try using jQuery instead of raw javascript. Take a look at

http://api.jquery.com/unload/

maybe something like
<script>
$( window ).unload(function() {
  alert('You are leaving the page');
});


might get you close to what you want.
Annalyzer replied on at Permalink Reply
Interesting. Works in IE, but not in Chrome or Firefox. Oh yay! Browser wars for the win. Ugh.