Hello @samarm,
I am not sure if you have tried it this way using javascript but it seems to have worked for someone else:
1) Add a Data Label to the Form
2) Change it to Visible - No, Literal - Yes
3) Add the following code to the Data Label Text:
<script> window.onbeforeunload = function(e) {return 'Are you sure? You will lose your data.';};</script>
referencing community article: https://community.k2.com/t5/K2-Five/Is-it-possible-to-display-a-message-on-form-redirection/td-p/103872
Regards,
BesM
K2 will not accept any liability for any issues arising from actions taken in respect of the information provided by any forum member.
One more article for you with explained tutorials to achieve this using jQuery:
https://vijaydk2guy.com/2017/06/02/basic-jqueryjavascript-samples-in-smart-forms/
Regards,
BesM