58
Views
4
Comments
Solved
JavaScript return to check if it came through the browser Back

Hello, I'm trying to get a return from this JavaScript


Inside the function it gets True, but outside or in the output variable for me to perform the logic it can't capture the value...


I've tried a few alternatives, but haven't succeeded yet


Can anyone tell me why? Thank you

Code:

window.onpopstate = function(event) {

    $parameters.Test = true; 

    console.log($parameters.Test);

};

    console.log($parameters.Test);

2022-03-26 19-41-06
Diego Oliveira
Solution

I managed to solve my problem with this code, with which I can't return to the page via the browser's back page


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

window.onpopstate = function(event) {

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

    var tl = document.title;

    document.title="";

    document.title= tl;

};

https://www.outsystems.com/forums/discussion/68440/disable-browser-back-button/
Shrinjala Singh´s comment

2019-01-07 16-04-16
Siya
 
MVP

To achieve this, you'll want to set up a callback mechanism, which involves calling a screen action from within your JavaScript code. For example, instead of just logging the `$parameters.Test` value with `console.log($parameters.Test);`, you would instead invoke `$actions.YourScreenAction(value)`. This action call triggers the execution of `YourScreenAction`, allowing you to handle operations based on the input value within that specific action.

2022-03-26 19-41-06
Diego Oliveira

Hello, I tried to do as you explained, but it didn't work...

I created a client action and called it in JavaScript to be able to manipulate it inside, but it didn't work... If you can give more details... 

2019-01-07 16-04-16
Siya
 
MVP

I have noticed that when we invoke a screen action inside the onpopstate callback error is 

"Invalid call of the 'BackButtonAction' client action of the 'MainFlow.Screen1' since the latter is not currently active. This is likely due to a platform's client action being used as an event handler or in a setTimeout function. Consider removing this call by using the 'On Destroy' event of the screen/block or moving your logic to a global client action. "

So looks like it is not possible to invoke screen action in this particular scenario :(

2022-03-26 19-41-06
Diego Oliveira
Solution

I managed to solve my problem with this code, with which I can't return to the page via the browser's back page


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

window.onpopstate = function(event) {

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

    var tl = document.title;

    document.title="";

    document.title= tl;

};

https://www.outsystems.com/forums/discussion/68440/disable-browser-back-button/
Shrinjala Singh´s comment

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