disable backspace on page navigation

1 posts, 0 answers
  1. dany7487
    dany7487 avatar
    88 posts
    Member since:
    Jan 2008

    Posted 02 Jul 2009 Link to this post

    Hi, everybody.

    I just want to share a solution I found to one of my problem. I wanted to disable the backspace funtionality of returning to the previous page. This worked fine for me and I hope it helps anyone:

    javascript code:

    var

     

    teclatextbox= false;

     

    function

     

    TeclaTextbox(presionada)

     

    {

    teclatextbox= presionada;

    }

     

    function

     

    BodyKeyDown(e)

     

    {

     

    var key;

     

     

    if (window.event)//IE

     

    key= window.

    event.keyCode;

     

     

    else//Firefox

     

    key= e.which;

     

    if(!e) var e = window.event;//take event

     

     

    if (key == 8 && !teclatextbox)//BACKSPACE and it is not inside a textbox

     

    {//stop the default behavior

       e.cancelBubble =

    true;

     

       e.returnValue =

    false;

     

     

       if (e.stopPropagation)

     

       {

         e.stopPropagation();

         e.preventDefault();

       }

     

       return false;

     

    }

     

    return true;

     

    }

    textbox events to permit backspace only inside the textboxes:

     

    <

     

    asp:TextBox ID="txbComentarios" runat="server" onkeydown="javascript:TeclaTextbox(true);" onkeyup="javascript:TeclaTextbox(false);" onblur="javascript:TeclaTextbox(false);"></asp:TextBox>

     

     

     

    Regards,
    Daniel.
     

Back to Top