How to block back button (plain JS)


I’m doing a project and I need to block back button in certain pages, can anybody help me?



@NathanaelA wrotes a good tutorial on his site :slight_smile:


Yesterday I found that page, but when I did that the app when run gives me a blue screen with errors =(

let me do it again to show the error.


it doesn’t found the “iRefuseToGoBack” value…

function backEvent(args) {
if (iRefuseToGoBack) { args.cancel = true; }


Yes, in the tutorial i didn’t found something for iRefuseToGoBack…

Maybe, @NathanaelA could help you :slight_smile:


first on loaded or something, register the event
if ( {, backEvent);
then you disable it with
function backEvent(args) {
args.cancel = true;

then on then when navigating to the page that you dont want it disabled on you run this
exports.unloaded = function() {
if ( {, backEvent);


On the pages you want to disable the back button for all u need to do is something like this global.iRefuseToGoBack = true once they are on that page and set it to false when they leave so then u can do something like

function backEvent(args) {
if (global.iRefuseToGoBack) { args.cancel = true; }


excelent! this answer works perfectly!

thank you @michaelsowah