Try to search Master Back button here https://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript
Daniel Luz wrote:
The above solution doesn't work anymore in newest Chrome browser.
Like Evert said all those years ago: don't start with the back button :).
I have something like this and it works
SyntaxEditor Code Snippet
$(document).ready(function(){ history.pushState(null, null, document.URL); window.addEventListener('popstate', function () { history.pushState(null, null, document.URL); }); });
Talk about a post bump :)
So the solution I suggested is not for disabling the Back button. I would avoid that temptation at all cost. My solution is for forcing a refresh of the actual page that was in the browser history, not to redirect to a different one or force the user stay in the current one.
Jasper, if you're trying to use that approach for this purpose (not for disabling the Back button) and still find it's not working, post some more detail about the behavior you're seeing and any errors you're getting.
Yes @Daniel, not at all trying to disable the backbutton ;)
But your solution to reignite the screen preparation isn't working anymore. Be aware of that!
My problem/solution:
At a client we we're having this problem of entering the screen with a certain id and doing some Ajax stuff which then registers/holds the selected item id in a SessionVar. Important: This can then be another item/id then the one in de URL GET parameter. When navigating to an other OS app the SessionVar/Id is used to get the correct/same item loaded in an other context. Then came the tricky part......when using the OS navigation to go back to the previous app everything works fine of course. But when the user decides to use the back button instead, the original state (from the initial URL GET parameters) is then loaded :(
I found a way that perfectly works for me:
When clicking a next item in the screen I will update the SessionVar + the URL parameter as well via the following method:
The SetCorrectURL is a default OS RunJavascript action which contains the following code:
history.pushState({}, """", '"+ GetEntryURL.URL +"');
(https://developer.mozilla.org/en-US/docs/Web/API/History_API#The_pushState().c2.a0method)
In this way when in the next OS app/screen is navigating back (via browser back button), the correct URL is always loaded, without even to launch the preparation again (performance plus)!
Again....this worked for me and is not about disabling the browser back button or reigniting the preparation ;)
Hello,This might be a solution for you with a few small changes: https://www.outsystems.com/forge/component/2932/browsers-back-button-protectionKR,Ruben Bonito