戻る

強制リロード
現在のページや指定したページのリロードについて

ページをリロード
location.reload();
現在のページをリロードします。
引数にtrueを渡すと、キャッシュからではなく、サーバーから強制的にリロードします。
(例)
location.reload(true);
上記はキャッシュを使わず強制リロードを実行します。
[強制リロードを実装する例]
下記は画面サイズが768px以下の場合は強制リロードをする例です。

copy
const breakpoint = window.matchMedia("(max-width: 768px)");
breakpoint.addEventListener("change", () => {
	window.location.reload(true); // キャッシュを無視して強制リロード
});
window.matchMedia
指定されたメディアクエリ文字列を評価し、結果を表すMediaQueryListオブジェクトを返します。
"(max-width: 768px)"
CSSのメディアクエリで、画面の幅が768ピクセル以下の場合にtrueとなる条件を指定しています。
const breakpoint = ...
breakpointという名前の定数に、window.matchMedia()の結果を格納しています。
この定数を使用し、画面の幅が768px以下かどうかを判定しています。

urlを指定して強制リロード
(例)
window.location.href = "https://www.xxx.com/";

window.location.href
現在のページのURLを表す文字列を返します。

サンプルのように現在のURLを再度設定することで、ページが再読み込みされます。
キャッシュを無視して最新のデータを取得するには、
window.location.reload()の引数にtrueを指定します。
(例)
window.location.reload(true);


戻る
back

Force Reload
Reloading the current page or a specified page

Reload the page
location.reload();
Reloads the current page.
If you pass true as an argument, it will force a reload from the server instead of from the cache. 
(Example)
location.reload(true);
The above executes a forced reload without using the cache.
[Example of implementing a forced reload]
The following is an example of a forced reload if the screen size is 768px or less.

copy
const breakpoint = window.matchMedia("(max-width: 768px)");
breakpoint.addEventListener("change", () => {
	window.location.reload(true); // Force reload, ignoring the cache
});
window.matchMedia
Evaluates the specified media query string and returns a MediaQueryList object that represents the results.
"(max-width: 768px)"
The CSS media query specifies a condition that is true if the screen width is 768 pixels or less.
const breakpoint = ...
The result of window.matchMedia() is stored in a constant named breakpoint.
This constant is used to determine whether the screen width is 768px or less.

Force reload by specifying URL
(Example)
window.location.href = "https://www.xxx.com/";

window.location.href
Returns a string representing the URL of the current page.

The page will be reloaded by setting the current URL again as in the sample.
To ignore the cache and get the latest data,
specify true as an argument to window.location.reload().
(Example)
window.location.reload(true);


back



著作権情報
ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。
ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、
または公開したりすることはできません。
当方は、ホームペーよびアプリ利用したいかなる理由によっての障害等が発生しても、
その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について
一切の責任を負わないものとします。