本文介绍了清除浏览器历史记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下代码来清除浏览器历史记录,它在Internet Explorer中正常运行但在Mozilla Firefox中无效。我该如何解决这个问题?

I wrote the following code to clear the browser history and it's working correctly in Internet Explorer but it does not work in Mozilla Firefox. How can I solve this problem?

<script language="JavaScript">
function DisablingBackFunctionality()
{
    var URL;
    var i ;
    var QryStrValue;
    URL=window.location.href ;
    i=URL.indexOf("?");
    QryStrValue=URL.substring(i+1);
    if (QryStrValue!='X')
    {
        window.location.href="http://localhost:8085/FruitShop/";
    }
}
</script>

我在< header> 部分。

推荐答案


  1. 不要试图打破后退按钮

  2. 而不是在您不希望返回的页面上使用location.replace(url)

此外,您的代码可以大大简化 - 但是请注意,它不会 CLEAR 历史记录。您无法清除历史记录,只保留一个页面进入历史记录或在您尝试时打破后退按钮

Also your code can be vastly simplified - but be aware it does not CLEAR the history. You cannot clear the history, only keep a page from getting into the history or as you try, break the back button

function DisablingBackFunctionality() {
// get the query string including ?
  var passed =window.location.search; 
// did we receive ?X
  if (passed && passed.substring(1) =="X") { 
// if so, replace the page in the browser (overwriting this page in the history)
    window.location.replace("http://localhost:8085/FruitShop/"); 
  }
}

这篇关于清除浏览器历史记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 10:27