I have create a site for case creation,the case is created and show a success message when i hit backspace button its going back to orginal page.how can i prevent the user hit backspace button and browser in Sites. How can solve this issues. Please let me know what am I doing wrong here


The backspace button is the universal browser button for navigate back. The only way to change this is to override the browser's normal behavior using javascript. Here is one of many jQuery functions to be found posted across the interwebs for doing just this:

//Prevents backspace except in the case of textareas and text inputs to prevent user navigation.
$(document).keydown(function (e) {
    var preventKeyPress;
    if (e.keyCode == 8) {
        var d = e.srcElement || e.target;
        switch (d.tagName.toUpperCase()) {
            case 'TEXTAREA':
                preventKeyPress = d.readOnly || d.disabled;
            case 'INPUT':
                preventKeyPress = d.readOnly || d.disabled ||
                    (d.attributes["type"] && $.inArray(d.attributes["type"].value.toLowerCase(), ["radio", "checkbox", "submit", "button"]) >= 0);
            case 'DIV':
                preventKeyPress = d.readOnly || d.disabled || !(d.attributes["contentEditable"] && d.attributes["contentEditable"].value == "true");
                preventKeyPress = true;
        preventKeyPress = false;

    if (preventKeyPress)
| improve this answer | |
  • thanks for replay greenstrok but the above code is not working in page and sites – user7292 Apr 1 '14 at 14:22
  • The above code is jQuery and would need to be added into a script tag in your Visualforce page, along with a link to jQuery from either a static resource or hosted. If you aren't familiar with Javascript and jQuery in Visualforce, this will be challenging to implement. – greenstork Apr 1 '14 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.