• Lance Havens 13
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
I have a Lightning Community that I would like to prevent the user from closing the window without first confirming they will lose any unsaved data.
hi all,

i have a requirement where in i want to alert a user whenever the user navigates away from the webpage without clicking on save button and navigating away instead of that..i tried the below code but its not working..
below is my code

 
<apex:page controller="VistAudit_VFC" action="{!createData}">
<body onload="myfunction()">
<script>
function myFunction()
{
alert("Are you sure you want to navigate away?");
}
</script>

     <apex:form >
  <apex:outputLabel value="Audit Visit" style="font-family:Times New Roman;font-size:18px"></apex:outputLabel><br></br>
 
    <div align="center" draggable="false" >
    <apex:commandButton value="Save" action="{!save}" onclick="myFunction();"/>
    </div>
..........
...........
.......
</apex:form>
</body>
</apex:page>

Can anyone please suggest as to how can i correct my code?


thanks,