My companies intranet needs the 'Backspace' key to be disabled. Can someone please let me know how to disable backspace key in IE7.
Thanks
My companies intranet needs the 'Backspace' key to be disabled. Can someone please let me know how to disable backspace key in IE7.
Thanks
I was working on how to disable enter key so the people who answered my thread might provide the answer.
http://www.dynamicdrive.com/forums/s...ad.php?t=34561
Kind regards
Dal
Yes, this works in IE 7 (others):
But it will disable its use in form fields as well as for activating the browser's back button function. The srcElement could be tested for though, that could allow it to still work normally in forms. Let me know if that is a concern.Code:<script type="text/javascript"> function killBackSpace(e){ e = e? e : window.event; var k = e.keyCode? e.keyCode : e.which? e.which : null; if (k == 8){ if (e.preventDefault) e.preventDefault(); return false; }; return true; }; if(typeof document.addEventListener!='undefined') document.addEventListener('keydown', killBackSpace, false); else if(typeof document.attachEvent!='undefined') document.attachEvent('onkeydown', killBackSpace); else{ if(document.onkeydown!=null){ var oldOnkeydown=document.onkeydown; document.onkeydown=function(e){ oldOnkeydown(e); killBackSpace(e); };} else document.onkeydown=killBackSpace; } </script>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
jscheuer1, thanks a lot for the quick reply.
Never did it strike my mind. What if the user wants to delete a value from the textbox (form) would the backspace work in that case? Can i have the backspace work inside a form (when focus is in a control) and when the focus is out somewhere, the backspace disabled?? Can this be done?
Thanks again.
Sure, though focus in a form isn't the best criteria because focus could be on a button in a form, in which case backspace would still activate the browser's back button function. As far as I can tell only text inputs, password inputs, file inputs, and textareas should be given an exception:
Let me know if any other elements should qualify for exception.Code:<script type="text/javascript"> function killBackSpace(e){ e = e? e : window.event;var t = e.target? e.target : e.srcElement? e.srcElement : null; if(t && t.tagName && (t.type && /(password)|(text)|(file)/.test(t.type.toLowerCase())) || t.tagName.toLowerCase() == 'textarea') return true;var k = e.keyCode? e.keyCode : e.which? e.which : null; if (k == 8){ if (e.preventDefault) e.preventDefault(); return false; }; return true; }; if(typeof document.addEventListener!='undefined') document.addEventListener('keydown', killBackSpace, false); else if(typeof document.attachEvent!='undefined') document.attachEvent('onkeydown', killBackSpace); else{ if(document.onkeydown!=null){ var oldOnkeydown=document.onkeydown; document.onkeydown=function(e){ oldOnkeydown(e); killBackSpace(e); };} else document.onkeydown=killBackSpace; } </script>
Last edited by jscheuer1; 07-21-2008 at 04:55 PM. Reason: code efficiency
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
me_myself (07-21-2008)
Thanks a lot jscheuer1
jscheuer1, my developers have .NET Atlas form validation code in it and they say it is causing conflict with this code and as a result the backspace code is not working. Do you know of any work around on how to get this code work along with the other?
Thanks.
There really shouldn't be any conflict unless the code you are speaking about already has a function named killBackSpace, as that is the only global in the code. However, I know nothing about .NET Atlas. It should be server side (at least most .NET code is), and so should not technically conflict. It may do things that render the code useless though. I would have to see the page where this is happening to even have a chance at determining what the problem is.
Please post a link to the page on your site that contains the problematic code so we can check it out.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
yes it really works in IE...
Bookmarks