Results 1 to 10 of 10

Thread: How to disable 'Backspace' key in IE7

  1. #1
    Join Date
    Aug 2007
    Location
    MO USA
    Posts
    106
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default How to disable 'Backspace' key in IE7

    My companies intranet needs the 'Backspace' key to be disabled. Can someone please let me know how to disable backspace key in IE7.

    Thanks

  2. #2
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    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

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Yes, this works in IE 7 (others):

    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>
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Aug 2007
    Location
    MO USA
    Posts
    106
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default

    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.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    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>
    Let me know if any other elements should qualify for exception.
    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

  6. The Following User Says Thank You to jscheuer1 For This Useful Post:

    me_myself (07-21-2008)

  7. #6
    Join Date
    Aug 2007
    Location
    MO USA
    Posts
    106
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default

    Thanks a lot jscheuer1

  8. #7
    Join Date
    Aug 2007
    Location
    MO USA
    Posts
    106
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default

    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.

  9. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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

  10. #9
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up JOhn thanx man

    yes it really works in IE...

  11. #10
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    Yes, this works in IE 7 (others):

    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>
    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.
    1) Hw to disable back button on browser after logout?
    2) and also hw to disable refresh buton or kill the previous cookie bafore generating a new one?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •