Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWebView Disable Backspace Key (But Not on HTML Fields)
Forum Updated to NodeBB v4.3 + New Features

QWebView Disable Backspace Key (But Not on HTML Fields)

Scheduled Pinned Locked Moved Solved General and Desktop
qwebviewkeyeventdisablebackspace
2 Posts 1 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maximo
    wrote on 8 Nov 2015, 22:35 last edited by
    #1

    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)?

    M 1 Reply Last reply 9 Nov 2015, 16:17
    0
    • M maximo
      8 Nov 2015, 22:35

      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)?

      M Offline
      M Offline
      maximo
      wrote on 9 Nov 2015, 16:17 last edited by
      #2

      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">
      $(document).ready(function(){
      
          // 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) {
                      window.history.back();
                  } else { // disable backspace
                      e.preventDefault();
                      return false;
                  }
              }
          });
      
      });
      </script>
      

      SOURCE: http://stackoverflow.com/a/17278620/105539

      1 Reply Last reply
      0

      1/2

      8 Nov 2015, 22:35

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved