30
Views
5
Comments
Disable browser back button
Question
Application Type
Reactive

Hi

I’m trying to disable or unutilized the browser back button, so that the user may not go back, I have tried the following JS code.

window.history.pushState(null, "", document.URL);        

      window.onpopstate = function() {

          window.history.pushState(null, "", document.URL);

  };

After clicking on back button user can not go back to previous page but browser title is changing for previous page, how to solve this please help.


Rank: #56

Hi Shrinjala,


Try the following JS:


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

window.addEventListener('popstate', function (event)

{

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

});


That should do the trick.



Kind Regards,
João

Rank: #916

Hi João,

I have tried this also but facing same issue.

Hi Shrinjala, 

Check the Navigation JavaScript API made available by the OutSystems Platform. There you will find the "registerBackNavigationHandler" function to manage the back button. Check if it fits your challenge.


P.S.: Allow me to challenge if you really need to control the back button? This is not a recommended behavior by many developers.


Cheers,

António Pereira

Hi Shrinjala,

Good morning!

Might this post can help:

https://www.outsystems.com/forums/discussion/9789/transactional-apps-and-the-back-button/

Kind regards,

Chris

Rank: #916

Thank you so much all for your response, issue is resolved,