QWebView Disable Backspace Key (But Not on HTML Fields)
-
wrote on 8 Nov 2015, 22:35 last edited by
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)?
-
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)?
wrote on 9 Nov 2015, 16:17 last edited byHere'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>
1/2