iPages

Wednesday, June 10, 2009

Handling BackSpace to avoid navigation to Back Page

This situation was faced in one of my current projects where client required Backspace functionality to be disabled so that it doesn't move to previous page if backspace is hit accidently. Although bacckspace was required to work in text areas and text boxes.

Here is a simple solution i found after some googling and experiments:

function conFunction()
{
return 'Please make sure you have filled in form correctly before navigating to next page!';
}
window.onbeforeunload = conFunction;

place this in Head tag of your page
onbeforeunload bydefault shows a confirm dialogue box, that helps preventing undesired navigation to backpage.

No comments:

Post a Comment