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)
QtWS25 Last Chance

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 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
    0
    • M maximo

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

      • Login

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