onunload() event - Best way to use this?

Posted by IramK on 22-Jan-2015 08:36

Hello,

I am trying to use the onunload event of a New record page and I am finding it quite difficult to get it to work on my usual browsers (Chrome and Firefox). The onunload obviously blocks the alert calls. I don't see an option of having an onbeforeunload() event in any of the pages. So may I know as to what is the best way to achieve an onunload functionality on my usual browsers? Kindly let me know.

Cheers.

Posted by Gian Torralba on 23-Jan-2015 08:33

Hello,

Please check if this code will fit your needs:

<script>
window.onbeforeunload = function() {
return "Did you save your stuff?"
}
</script>

Thank you,

Gian

All Replies

Posted by Gian Torralba on 22-Jan-2015 08:53

Hello,

May I know what script are you trying to run on the unload event? Are you trying to display an alert popup? You can try adding this JQuery script to that page.

$(window).unload(function() {
alert( "Handler for .unload() called." );
});

Thank you,
Gian

Posted by IramK on 22-Jan-2015 08:56

I've tried it. It doesn't work. I've even tried to call a function in the onunload event of a page and then place the alert in that function using a script component. Still doesn't work.

Posted by Gian Torralba on 22-Jan-2015 09:17

Hello,

If you just need an alert script you may use the following:



Thank you,
Gian

Posted by IramK on 23-Jan-2015 03:15

[mention:c5dec1ce5a5948c5a25cf4bcaeb7db77:e9ed411860ed4f2ba0265705b8793d05] : Sorry dint get the code.

Posted by Gian Torralba on 23-Jan-2015 08:33

Hello,

Please check if this code will fit your needs:

<script>
window.onbeforeunload = function() {
return "Did you save your stuff?"
}
</script>

Thank you,

Gian

Posted by IramK on 23-Jan-2015 08:37

Yes that works. Finally!

Cheers.

This thread is closed