JavaScriptを使用してページをリロードする方法 質問する

JavaScriptを使用してページをリロードする方法 質問する

JavaScript を使用してページをリロードするにはどうすればよいですか?

すべてのブラウザで機能する方法が必要です。

ベストアンサー1

JavaScript 1.2以降

短縮版:

location.reload();

ロングバージョン(ショートバージョンと同じ):

window.location.reload();

一部のブラウザでは、キャッシュを強制的にクリアするオプションのブール型パラメータ(Ctrl+Shift+R に類似)をサポートしていますが、これは非標準であり、サポートとドキュメントが不十分であるため、通常は使用しないでください。

//Force a hard reload to clear the cache if supported by the browser
window.location.reload(true);

JavaScript 1.1

window.location.replace(window.location.pathname + window.location.search + window.location.hash);
// does not create a history entry

JavaScript 1.0

window.location.href = window.location.pathname + window.location.search + window.location.hash;
// creates a history entry

おすすめ記事