posts - 5 , comments - 1 , trackbacks - 0

ASP.Net Prevent navigation on Back Space button

Web sites will usually redirect user to previous page, if Back Space button is pressed. I have recently got the requirement to prevent user from navigating during this scenario.

For this, we have to prevent back space button’s event fire on key down. But, if focus is on text box/text area then Back Space should work.

Below code will work if you have this as a requirement:

// Prevent the backspace key from navigating back.
$(document).keydown(function (e) {
var doPrevent;
if (e.keyCode == 8) {
var d = e.srcElement || e.target;
if (d.tagName.toUpperCase() == ‘TEXT’ || d.tagName.toUpperCase() == ‘TEXTAREA’ ) {
doPrevent = d.readOnly || d.disabled;
}
else
doPrevent = true;
}
else
doPrevent = false;

if (doPrevent)
e.preventDefault();
});
 

-Karthick Raju

Print | posted on Friday, November 4, 2016 6:38 AM | Filed Under [ Asp.Net JavaScript ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 

Powered by: