193
Views
3
Comments
How to detect browser back button in reactive app
Application Type
Reactive

I have the following requirement scenario.

Scenario : 

I have two screen (Home,Detail)  in reactive application and I want to display OutSystems Popup message Block when press the browser back button in Detail screen.

In pop-up message  have 2 buttons ,Cancel and OK. 

When [OK] button clicked  I want to go out of application and back to Home screen.

Otherwise, When [Cancel]  button clicked I want to stay in Detail screen.


 Issue:  

When [Cancel]  button clicked, the On Destroy event is called and the edited data in the Detail screen  is erased because of reactive LifeCycle event.How to solve this issue and I have attach oml file in the following.

Reference docs:

https://success.outsystems.com/documentation/how_to_guides/front_end/how_to_prevent_end_users_from_losing_unsaved_changes/


Thanks & Regards 

Aung


BrowserBack.oml
スクリーンショット 2023-10-24 191630.png
2021-06-03 11-03-21
Anubhav Rai

Hi Aung,
You can bypass the logic by adding a new local boolean variable which will change when you click on cancel so that your existing flow (ondestroy and other actions) knows this is not the normal flow and by this, your existing logic will not execute when you click on cancel button.
1.) Set the Boolean Local variable default value as false.
2.) On clicking on cancel set the value to true.
3.) Add an if check at the start of your existing action which is triggering automatically (ondestroy and other) (if the boolean variable is false then it should go to normal flow otherwise it should end.)


Please let me know if you have more queries.

Regards,
Anubhav

UserImage.jpg
Aung Than Htut

Hi Anubhav ,
Thanks for your answer and appreciate .My issue is that when press the browser back button, I'm just want to display of OutSystems Popup dialog and not at press cancel button of Popup dialog.

Best regards, 

Aung

UserImage.jpg
João Pais

Hello Aung,

You can add an event listner in javascript to detect if the browser's back button was clicked:

window.addEventListener('popstate', function(event) {  // Check if the user has navigated back  console.log("User has navigated back."); }); 



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