35
Views
21
Comments
Solved
[Check Has Changes] Back button refreshing page when clicking on "Cancel"
check-has-changes
Reactive icon
Forge asset by Hugo Francisco, Pedro Raposo
Application Type
Reactive

Hi, we are trying to trigger a popup confirmation message whenever user is trying to leave page without saving changes.

It works fine when we try to refresh or close the page, but when we are trying to go back through the browser's back button and we click on cancel leaving the page, it refreshes all the page content.

Can you please help us solve this problem?

Thank you

2025-09-04 15-20-02
Hugo Francisco
Solution

@Carla Varela new version published :)
If you are happy with the component mark this message as the solution :)
Thanks for using our component

UserImage.jpg
Carla Varela

Yes, sure.

You're welcome, thank you :-)

2022-06-09 12-06-46
Pedro Raposo

Can you provide an OML or OAP with the example you are talking about so that I can check it faster?

UserImage.jpg
Carla Varela

Hello Pedro,

In the demo, when we make changes and then we click on browser's back button and click on cancel exiting the page without saving changes, it refreshes the screen also.

We want to keep all the content in the page and not refresh it every time we click on cancel going to previous page (browser's back button).

2024-12-02 12-15-17
Aravind EONE

Hi @Carla Varela ,

I have fixed it using some javascript changes. now click on cancel won't clear the field values instead replaced from snapshot.

After the screen re-initializes, checks the restore flag and reapplies the snapshot to inputs (and dispatches input/change events so OutSystems picks them up). 

Please find the OML attached for your reference.

CheckHasChanges_WebBlock_Aravind_OML.oml
UserImage.jpg
Carla Varela

Thanks for your reply @Aravind I, but the problem remains.

The main problem isn't the fact that it refreshes the content, but the fact that it refreshes all the page after clicking on Cancel button in the pop up of unsaved changes.

2024-12-02 12-15-17
Aravind EONE

Hmm..

The platform is very likely re-initializing the screen (OutSystems remounts the screen) and JS prevention alone can’t stop that it seems.

UserImage.jpg
Carla Varela

But it works fine when we try to refresh page or close it by clicking on cancel button.

2025-08-07 06-30-56
Amit J
Champion

Browser back button → handled via popstate, so the page doesn’t refresh when user cancels.

For the browser back button, use JavaScript to intercept popstate (the event triggered when pressing back):

window.addEventListener("popstate", function (event) {

    if ($public.FeedbackMessage && $public.FeedbackMessage.HasChanges) {

        if (!confirm("You have unsaved changes. Do you really want to leave?")) {

            history.pushState(null, null, location.href); // cancel back

        }

    }

});


This cancels the back button if user chooses Cancel

So you can use the above JavaScript to stop unload the page on clicking on Back btn

UserImage.jpg
Carla Varela

Hello @Amit J, where should I post this code, please?


2025-08-07 06-30-56
Amit J
Champion

On change of the form value of any widget or elements you can call in JavaScript node this code


2025-08-07 06-30-56
Amit J
Champion

Or

Steps

Add the CheckHasChanges Forge component to your screen (to detect unsaved form changes).

Create a JavaScript node (or use a RunJavaScript action in screen OnReady).

Paste this code:




window.addEventListener("popstate", function (event) {

    // Check if OutSystems has detected changes

    if ($public.FeedbackMessage && $public.FeedbackMessage.HasChanges) {

        var leave = confirm("You have unsaved changes. Do you really want to go back?");

        if (!leave) {

            // Cancel back navigation

            history.pushState(null, null, location.href);

        }

    }

});

history.pushState(null, null, lo

cation.href);

2025-08-07 06-30-56
Amit J
Champion

Are you able to now fix it or need a sample oml ?

UserImage.jpg
Carla Varela

Hello @Amit J , if you don't mind to send it, please.

I would appreciate

2024-12-02 12-15-17
Aravind EONE

Still its clearing the form fields on click of cancel @Amit J 

2025-08-07 06-30-56
Amit J
Champion
Backbtn.oml
2025-09-04 15-20-02
Hugo Francisco

Hello @Carla Varela, how are you today?

As one of the creators of the forge component you are trying to use let me first thank you for using it :)

Can you test the following page to see if this is the desired behaviour?

https://personal-aka1miuc.outsystemscloud.com/Example/CheckHasChanges

Thanks

UserImage.jpg
Carla Varela

Hello Francisco,

Yes, that's exactly the desired behaviour.

How did you made it?

Thank you


2025-09-04 15-20-02
Hugo Francisco

I'll publish this new version and then you can consume it :)

UserImage.jpg
Carla Varela

Thank you @Hugo Francisco.

Could you please let me know whenever you publish it.

Thanks

2025-09-04 15-20-02
Hugo Francisco
Solution

@Carla Varela new version published :)
If you are happy with the component mark this message as the solution :)
Thanks for using our component

UserImage.jpg
Carla Varela

Yes, sure.

You're welcome, thank you :-)

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.