当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Disable IE back Button

问题描述:

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?

网友答案:

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?."; };
网友答案:
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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: