Triggering an alert when leaving a form that hasn't been saved


I am building a page that requires a user to save before leaving or the user will lose all completed information. I thought I could accomplish this by using conditional logic, but I am having a hard time figuring which type of condition needs to be used.

Desired outcome: When a user clicks on something to leave the page (be it home, or any tab that will take them to a new page), if they have not clicked on save, I want to fire an alert message telling them if they leave the page before saving, they will lose all of their entered information. Anyone know how to accomplish this?

Global Variable.

Set it to Zero on pageLoad. Then when navigating away check if that Global Variable is zero. If so do something.

Thank you for your response. Do I make the save button the global variable? I assumed I used global variables when wanting variables to persist across pages. I want to fire an alert when a user clicks a nav item that would take them away from the page if they did not click on the save button prior to clicking on the nav item. Would I still use global variables in this case?

In your case, does zero mean no action has been taken on the save button?

Something like this maybe:

saveBeforeExit.rp (78.1 KB)

The design is ugly. Sorry!

Basically, the User types something, the page knows something has been done. If Save isn’t clicked the Global Variable is set to 1. On Save its set to 0. When the user tries to leave, it checks to see if the Global Variable is 0, if not then show modal.

1 Like

Awesome! Worked like a charm! Thank you!

Hey, I stumbled upon this while trying to solve the same issue.

While the provided solution surely works, is there not an easier way how to do this? Meaning, when I have a full fledged website with navigation as a master etc., I don’t feel that writing into master these conditions for every navigation entry is the best way (but maybe the only way).

Is there nothing like OnPageClose, OnPageUnload, or something like that?

Thank you for your help in advance.

Real websites have state management which can be used for this sorta thing. Axure does not.

If you figure out a slicker way of doing this, please upload it! I love seeing new solutions

@jlhelmers Thanks for the explanation. If I’ll figure something out, I will share it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.