Forum Discussion

Former_Member's avatar
Former_Member
Accelerator III
9 years ago

Form onUnload Event

Hi all, I am using Aras 11SP5,client FireFox 38ESR In the Form Event I have one onUnload event, but I found when I close the windows, the event seem doesn't trigger? Thanks,    

5 Replies

  • eli_donahue's avatar
    eli_donahue
    Community Manager
    Hi Mark, Can you describe your use case? Do you see the same result when setting the event as an onBeforeUnload form event? Eli
    Eli Donahue Aras Labs Software Engineer
  • Hi Eli When user insert/edit the item and close (×) the Item form using upper left corner –□× (not Save,Unlock&Close) I want the system can auto unlock this item , so in the form event I have one onUnload event like below <p style="padding-left: 30px;">function MyFunc() {</p> <p style="padding-left: 60px;">var itm = document.thisItem;</p> <p style="padding-left: 60px;">var chk =itm.fetchLockStatus();</p> <p style="padding-left: 60px;">if (itm.fetchLockStatus()!="0" )</p> <p style="padding-left: 60px;">{ top.onUnlockCommand(); } }</p> <p style="padding-left: 30px;">alert("check the method onunload");</p> <p style="padding-left: 30px;">window.attachEvent("onunload", MyFunc); top.MyFunc = MyFunc;</p> But I try the onUnload or onBeforeUnload event the system doesn't trigger the method and show the alert("check the method onunload") Thanks,
  • eli_donahue's avatar
    eli_donahue
    Community Manager
    Hi Mark, I am seeing the same behavior you are - the onUnload and OnBeforeUnload form events don't appear to execute their method code. I'll file an issue for this behavior to be reviewed. In the meantime, you can use an HTML field on your form to load your script. I tested the following sample to confirm that it executes before the form closes. It just calls the browser's default "are you sure you want to leave" dialog with the custom message passed via event.returnValue, but you could perform any logic inside the function.
    <script>
        window.addEventListener("beforeunload", function(event){
            event.returnValue = "unloading now";
        });
    </script>
    Eli
    Eli Donahue Aras Labs Software Engineer
  • Hi Eli It work, but when I use the button of  "Save,Unlock&Close ", the browser show “are you sure you want to leave” every time. Thanks,