我想实现一个 JavaScript 代码,它说明了这一点:如果页面完全加载,立即刷新页面,但只能刷新一次。我被困在“只有一次”:
window.onload = function () {window.location.reload()}
这给出了一个没有“只有一次”的循环。如果这有帮助,就会加载 jQuery。
我想实现一个 JavaScript 代码,它说明了这一点:如果页面完全加载,立即刷新页面,但只能刷新一次。我被困在“只有一次”:
window.onload = function () {window.location.reload()}
这给出了一个没有“只有一次”的循环。如果这有帮助,就会加载 jQuery。
我会说使用哈希,像这样:
window.onload = function() {
    if(!window.location.hash) {
        window.location = window.location + '#loaded';
        window.location.reload();
    }
}
当我遇到这个问题时,我搜索到这里,但大多数答案都试图修改现有的 url。这是另一个使用 localStorage 对我有用的答案。
<script type='text/javascript'>
(function()
{
  if( window.localStorage )
  {
    if( !localStorage.getItem('firstLoad') )
    {
      localStorage['firstLoad'] = true;
      window.location.reload();
    }  
    else
      localStorage.removeItem('firstLoad');
  }
})();
</script>
<script type="text/javascript">
$(document).ready(function(){    
    //Check if the current URL contains '#'
    if(document.URL.indexOf("#")==-1){
        // Set the URL to whatever it was plus "#".
        url = document.URL+"#";
        location = "#";
        //Reload the page
        location.reload(true);
    }
});
</script>
由于 if 条件,页面只会重新加载一次。我也遇到过这个问题,当我搜索时,我找到了这个不错的解决方案。这对我来说很好。
检查此链接它包含一个 java 脚本代码,您只能使用该代码刷新您的页面一次
刷新页面的方法不止一种:
解决方案1:
要在每次打开时刷新页面,请使用:
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</head>
解决方案2:
<script language=" JavaScript" >
<!-- 
function LoadOnce() 
{ 
window.location.reload(); 
} 
//-->
</script>
然后改变你说
<Body onLoad=" LoadOnce()" >
解决方案3:
response.setIntHeader("Refresh", 1); 
但是此解决方案将多次刷新页面,具体取决于您指定的时间
我希望这会帮助你
<script>
function reloadIt() {
    if (window.location.href.substr(-2) !== "?r") {
        window.location = window.location.href + "?r";
    }
}
setTimeout('reloadIt()', 1000)();
</script>
这完美地工作