How Do I Prevent a Backspace from Navigating Away from Page?

How Can We Help?

How Do I Prevent a Backspace from Navigating Away from Page?

< Back

Answer

How many times have you filled out a large XMPro form only for a postback to lose focus on the next input field, and you press backspace which navigates back in history and all your captured information is lost?

Well, here is a small solution to this which can be XMPro system/application wide or page specific you choose.

The solution was found online using jQuery as a library, which you can include into the relevant header pages as needed.

The following piece of jQuery script will allow you to capture the backspace event when called on a where the focus is not on an input field, that is, text box, large text box, etc.

The following script has been included into the Action Item and Process Item “<head>” element of the pages after the jQuery library has been included.

<script type="text/javascript">
$(document).keydown(function(e) {
var element = e.target.nodeName.toLowerCase();
if ((element != 'input' && element != 'textarea') || $(e.target).attr("readonly")) {
if (e.keyCode == 8) {
return false;
}
}
});
</script>

It is pretty straightforward and it is easy enough to display a warning message to the user as well.

Note: This is not limited to any version of XMPro.

Comments are closed.

This is the legacy version of the XMPro Documentation site. For the latest XMPro documentation, please visit documentation.xmpro.com

X