强制JavaScript刷新一次

Forcing JavaScript to refresh once

如何强制 Javascript 只刷新 onload 一次?我的看法:

$(window).ready(function(res){
    var hash = '#refreshed';
    if(window.location.hash != hash) window.location.replace(window.location + hash)
});

但这不会刷新页面。 有什么想法吗?

散列的用途是更改它不会重新加载页面。

从那时起,您需要在更改哈希后使用 MDN: Location.reload()

您尝试过使用 location.reload 吗?

The Location.reload() method Reloads the resource from the current URL. Its optional unique parameter is a Boolean, which, when it is true, causes the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache.

示例:

$(window).ready(function(res){
  var hash = '#refreshed';
  if(window.location.hash != hash) {
    window.location.replace(window.location + hash); // add your hash
    document.location.reload();                      // reload the page
  }
});