1

I have a application where i have disabled the back button of IE8 by using the following code.

window.history.forward();
function noBack() {

    window.history.forward();
}

I know this code takes the page back and again moves the page forward. i have called a function onload of the page which makes a textbox read only. i have used the following code to make it read only.

$("#IDofTheTextBox").attr('readonly',true);

but if i select the textbox and try to edit by pressing "BackSpace" button, IE back button is getting invoked and the textbox which was readonly is not readonly anymore. Can anyone help me how to solve this issue?

Akshar A K
  • 392
  • 5
  • 14
  • 23
  • 7
    **Why** would you break the back button? It's horrible UX.. – MarcoK Feb 23 '13 at 06:55
  • 1
    Did you try setting the `readonly` property inside the HTML itself – Harsha Venkataramu Feb 23 '13 at 06:56
  • Duplicate : http://stackoverflow.com/questions/780718/how-to-disable-back-button-in-ie-and-firefox – Arpit Feb 23 '13 at 06:57
  • The application requirement is like i shouldn allow to move back... – Akshar A K Feb 23 '13 at 06:58
  • Yes. but there is a condition to check where if the condition is true then the field will be readonly. else editable. So cant handle in HTML.. – Akshar A K Feb 23 '13 at 06:59
  • 1
    Have you considered the following. A person is looking at you web after looking at a previous web site. They want to go back to that web site and are unable to do so. So what do you think that they will reflect on your web site and company? I, for one, would not visit your web site again and would go else web to do my business as I think this is poor form. – Ed Heal Feb 23 '13 at 07:06
  • possible duplicate of [Disabling Back button on the browser](http://stackoverflow.com/questions/87422/disabling-back-button-on-the-browser) – Barmar Feb 23 '13 at 07:20
  • i understand your point Ed Heal. but the customer himself want this. Its not me or my company..:) – Akshar A K Feb 23 '13 at 07:48
  • 1
    https://twitter.com/codinghorror/status/133821946239516672 – Kyle Strand Feb 23 '13 at 08:16
  • 2
    I can think of no justifiable reason for a web page to break browser functionality. – Kyle Strand Feb 23 '13 at 08:17

3 Answers3

4

The answer is simply "NO"

If you're trying to prevent the user from losing their work, try something like:

window.onbeforeunload = function() { return "Are you sure want to leave this page?."; };
coder
  • 13,002
  • 31
  • 112
  • 214
2
function changeHashOnLoad() {
     window.location.href += "#";
     setTimeout("changeHashAgain()", "50"); 
}

function changeHashAgain() {
  window.location.href += "1";
}

var storedHash = window.location.hash;
window.setInterval(function () {
    if (window.location.hash != storedHash) {
         window.location.hash = storedHash;
    }
}, 50);

You add the above javascript functions in the js file and onload call the function changeHashOnLoad().

its working fine in IE8. i just tested it.

Akshar
  • 111
  • 1
  • 11
  • Its disaling my backspace button. but if i keep the backspace button pressed for few seconds then again its the same scenario...! – Akshar A K Feb 23 '13 at 08:04
0

I dont know what your page is trying to do... but this is what we do:

We have an assessment where we do not want the browser buttons enabled... because we run ajax/logic when the user hits next/back etc (to determine what to display next based on their inputs). Back and forward buttons can muddy that process up.

So..... we have users open our assessments in A NEW WINDOW so the back button is already disabled...(there is no prior history in a new window). Then, Our next/back buttons use window.location.replace(url); This will prevent a history item from being created. Therefore, the back/forward buttons are never enabled and they must use the next/prev buttons to navigate our tool.

I would not try to muck with the buttons outside of something like the example I provided.

Nawlbergs
  • 1,012
  • 1
  • 11
  • 10