prevent backspace from navigating back

Hello everyone.
I need to prevent my application from navigating back when “backspace” key is hit. Application is very massive, has some 75 containers, each may have sub-containers and many controls, and document.onkeydown = function (event) {…code to prevent hit, allow just input fields to use it…} is not working (probably some Xojo overload on this)
Any ideas?

Unless you programmed backspace to do that, I am not aware that Xojo does that by itself.

Unless we are talking about a web app viewed in Chrome.

A little further on Michel’s comment.

There are a few add-ons/plugins for chrome that will disable the “back” action when Backspace is pushed.
For Chrome

In firefox, you can set the Integer pref browser.backspace_action to 2 on the about:config page to disable the backspace action.

BTW I don’t think JavaScript can prevent backspace navigation at least in Chrome, since the application gets the key before the DOM.

There one way in Xojo, though : as long as a TextField or TextArea has focus, Chrome backspace navigation is inhibited.

I just tried with a 10x10 pixels WebTextArea with no focus ring. It is very discrete and as long as it or another text control has focus, backspace does not trigger page back.

If you’re using Chrome, you should really try a different browser.

Actually, on the Web, one must make sure of the app with all current browsers : On Mac Safari, On PC Internet Explorer and Edge, on both Chrome, FireFox, Opera at least, plus Android native browser, Android Chrome, Android FireFox, iOS Safari.

Each of them has its own idiosyncrasies.

I need this cross-browser.
You may do a little test.

  • Create (signle page) application in Xojo (Blank page is just fine, as long as there is NO INPUTS such as textfield or textarea).
  • Start the application
  • Copy the address from address bar
  • Navigate anywhere else (say
  • Paste your copied address* to browser’s address bar and hit enter - You have re-navigated to your blank page
  • hit backspace! You are once again on your previous page (

I need to prevent this for ALL browsers.

  • Do not hit back! Paste-Enter

Sometimes if you want a car without a body, wheels and an engine, it stops being a car.

The trick of having a Focused TextField that prevents backspace navigation should suffice. Heck, a 1x1 TextField is enough.

You might want to set the WebSession.ConfirmMessage to at least give the user a warning message if they try to navigate away from your app using backspace, back button or anything else.

Try a Desktop app.

It is a kind of extremely difficult since we are talking about a request in application with about 6 million lines of code :slight_smile:

Good luck…

Here is an off the wall suggestion …

This may or may not be possible but you might be able to write a proxy server that the Web browser connected to then that connected to the Xojo Web app. It could maybe intercept some navigation stuff.

Just a crazy thought but certainly easier than what it might take to modify your huge app.

I suppose you could also create a customized Web Server app or get a custom one built by somebody like

How about something like this:

No idea how to do it in Xojo as I don’t use it for webapps.

It works :slight_smile:

[quote=276454:@Alain Bailleul]How about something like this:

No idea how to do it in Xojo as I don’t use it for webapps.[/quote]
Incredible! Works… Many Thanks Alain

As anyone incorporated the code into a Xojo webapp?