Nominate our 2022 Qt Champions!

QWebView Disable Backspace Key (But Not on HTML Fields)

  • In QWebView, pressing the backspace key causes the page to go back. How can I disable that key to have the power to do that functionality, while not disabling the backspace key on HTML fields, and not disabling my ability to do history.back() in a Javascript function (as in when I want a Go Back button)?

  • Here's the solution. You have to do it in Javascript. Ensure jQuery is loaded in your web pages (even the IFRAME/FRAME ones) and then apply this code:

    <script type="text/javascript">
        // Disable backspace key except in fields.
        $(document).keydown(function(e) {
            var elid = $(document.activeElement).is('INPUT, TEXTAREA') ;
            if (e.keyCode === 8 && !elid) {
                if(e.ctrlKey) {
                } else { // disable backspace
                    return false;