# Trigger a Custom Event when a Page is Unloading

**URL:** <https://forum.bubble.io/t/trigger-a-custom-event-when-a-page-is-unloading/315533>\
**Category:** Need help\
**Created:** [April 2, 2024, 2:44am UTC](https://forum.bubble.io/t/trigger-a-custom-event-when-a-page-is-unloading/315533 "2024-04-02T02:44:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![edipguney](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@edipguney](https://forum.bubble.io/u/edipguney)\
**Post date:** [April 2, 2024, 2:44am UTC](https://forum.bubble.io/t/trigger-a-custom-event-when-a-page-is-unloading/315533/1 "2024-04-02T02:44:52Z")

</div>

I want to run a custom event while the user leaving the page. I have tested the custom event, it is working, however, I want to run it while the user is leaving the page.

thanks…

---

<div class="post-metadata">

**Author:** ![rpetribu](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/rpetribu/32/90852_2.png) [@rpetribu](https://forum.bubble.io/u/rpetribu)\
**Post date:** [April 2, 2024, 3:05am UTC](https://forum.bubble.io/t/trigger-a-custom-event-when-a-page-is-unloading/315533/2 "2024-04-02T03:05:14Z")

</div>

I am sure that there is a plugin for this…

---

<div class="post-metadata">

**Author:** ![edipguney](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@edipguney](https://forum.bubble.io/u/edipguney)\
**Post date:** [April 2, 2024, 4:18am UTC](https://forum.bubble.io/t/trigger-a-custom-event-when-a-page-is-unloading/315533/3 "2024-04-02T04:18:17Z")

</div>

I am sure that someone has solved it without a plugin.

---

<div class="post-metadata">

**Author:** ![tylerboodman](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/tylerboodman/32/242142_2.png) [@tylerboodman](https://forum.bubble.io/u/tylerboodman)\
**Post date:** [April 2, 2024, 7:19am UTC](https://forum.bubble.io/t/trigger-a-custom-event-when-a-page-is-unloading/315533/4 "2024-04-02T07:19:41Z")

</div>

There’s no Bubble native event like “When User leaves page” to detect this, but you could use Javascript and thats exactly what plugins do 😊 [Page Close Event / Quit / Exit Plugin | Bubble](https://bubble.io/plugin/page-close-event--quit--exit-1621764699423x344379196288794600)

Just looking at the plugin code (and asking GPT to analyze the update function and the script it loads on the page) there’s a bit more going on than just a simple patch we can do in Bubble with Toolbox plugin.

---

<div class="post-metadata">

**Author:** ![edipguney](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@edipguney](https://forum.bubble.io/u/edipguney)\
**Post date:** [April 3, 2024, 5:10am UTC](https://forum.bubble.io/t/trigger-a-custom-event-when-a-page-is-unloading/315533/5 "2024-04-03T05:10:47Z")

</div>

Actually, I have noticed that file uploader leaves orphaned files if thing has not been created, so I decided to delete after user leave the page. I have tried the plugin, it does not work properly. I found this solution.

> [@\[SOLVED\] Preventing "orphaned" files - How would you handle it?](https://forum.bubble.io/t/solved-preventing-orphaned-files-how-would-you-handle-it/63664):
>
> Consider a user profile page that allows the user to update their picture. As a UI requirement, the updated profile picture gets saved only when the user explicitly hits the Save button. Now, if the user changes their mind and hits Cancel instead of Save, the uploaded image is already in Bubble’s storage. To practice good housekeeping, the uploaded image should be deleted, and the previous profile image should be restored. That should be possible with a workflow on the Cancel button. However, …

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/bubble/original/3X/2/8/2847faa74692c2ffa5d939d3dc3724cdd060d247.png) [@system](https://forum.bubble.io/u/system)\
**Post date:** [June 11, 2024, 2:44am UTC](https://forum.bubble.io/t/trigger-a-custom-event-when-a-page-is-unloading/315533/6 "2024-06-11T02:44:58Z")

</div>

Closed on June 11, 2024, 2:44am UTC

This topic was automatically closed after 70 days. New replies are no longer allowed.
