This is a migrated thread and some comments may be shown as answers.

disable backspace on page navigation

0 Answers 85 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
dany7487
Top achievements
Rank 1
dany7487 asked on 02 Jul 2009, 03:43 PM
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.
 

No answers yet. Maybe you can help?

Tags
Ajax
Asked by
dany7487
Top achievements
Rank 1
Share this question
or