如何禁用浏览器中的前进,后退和刷新功能?

问题描述:

有人可以使用javascript或Jquery禁用浏览器的后退,前进和后退按钮以及右键单击菜单功能吗?我曾尝试禁用过这样的后退按钮

Hi Can any one help to disable browser back,forward and back button and right Click Menu functionality using javascript or Jquery?I have tried disabling the back button like this

function disableBackButton() {
           window.history.forward();
       }
       setTimeout("disableBackButton()", 0);



我在Body onload事件中调用了此函数.我怀疑我们需要将该代码放在``调用页面''或``被调用页面''中的位置.假设我有两个这样的页面,例如FirstPage.aspx和SecondPage.aspx.当我单击浏览器的后退按钮时,第一页到第二页不应转到FirstPage.aspx.

请就此



I have called this function in the Body onload event.I have a doubt that where we need to put this code in the Calling page or Called Page.Suppose i have two pages like this FirstPage.aspx and SecondPage.aspx.When i navigate from the First Page to Second Page when i click back button of the browser it should not go to FirstPage.aspx.

Please help me regarding this

进行帮助,不要这样做,您不应该迷惑浏览器功能.浏览器是我的,我希望我的后退\前进和刷新按钮能够正常工作!!

通常,当人们发布这样的问题时,这是因为由于诸如缓存之类的事情,他们不了解如何控制来自站点的数据流.

为什么不回到首页?这就是互联网工作方式的预期行为".是因为某些内容已被填充,还是一些安全问题?根据您要阻止用户执行的操作(除了返回!),还有另一种方法可以实现此目的.
Don''t do this, you shouldn''t be tring to mess with browser functionality. The browser is mine, I want my back \ forward and refresh buttons to work!!

Usually when people post questions like this, it''s because they don''t understand how to control the flow of data from the site, due to things like caching etc.

Why shouldn''t it go back to Firstpage? That''s the ''expected behaviour'' of how the internet works. Is it because something has been filled in, some security issue? Depending on what it is you''re trying to stop the user doing (other than going back!) there''s probably another way to achieve this.


是的,我们当然不能禁用浏览按钮不是其特定于浏览器的原因,但我们可以禁用某些功能键,例如F5刷新浏览器,并在IE资源管理器中禁用F1的帮助"菜单,这是将禁用浏览器F5按钮刷新浏览器内容的代码小精灵.

yes we certainly can not disable browse buttons cause its not ours its browser specific but we can disable certain function keys like F5 to refresh browser and F1 for Help menu in IE explorer, here is the code spinet that will disable browser F5 button to refresh browser contents.


document.onkeydown = function() {
    if(event.keyCode == 116) {
            event.returnValue = false;
            event.keyCode = 0;
            return false;
           }
}



将此代码放在JavaScript中的任何位置,并且该特定页面的F5键盘快捷键将被禁用. 116是F5的数字代码.您可以通过为其找到数字代码来禁用任何按钮



place this code anywhere in JavaScript and your keyboard short cut key for F5 will be disabled for that particular page. 116 is a numeric code for F5. You can disable any button by finding numeric code for it


window.history.forward(1);
document.attachEvent("onkeydown",my_onkeydown_handler);
函数my_onkeydown_handler()
{
开关(event.keyCode)
{
案例116://``F5''
event.returnValue = false;
event.keyCode = 0;
//window.status =我们已禁用F5";
休息;
}
}
document.onmousedown = disableclick;
status =不允许右键单击";
函数disableclick(e)
{
if(event.button == 2)
{
alert(状态);
返回false;
}
}

这是在浏览器中禁用右键单击和F5键的代码
window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler()
{
switch (event.keyCode)
{
case 116 : // ''F5''
event.returnValue = false;
event.keyCode = 0;
//window.status = "We have disabled F5";
break;
}
}
document.onmousedown=disableclick;
status="Right Click is not allowed";
function disableclick(e)
{
if(event.button==2)
{
alert(status);
return false;
}
}

heres the code to disable the right click and F5 key in your browser