10
9

More than 5 years have passed since last update.

ページ読み込み種類の判別(リロード、ブラウザバック等)

Posted at

Navigation Timing API を使用して判別

window.performance.navigation オブジェクトは 2 個の属性を格納しており、
ページの読み込みが何によって起こされたか (リダイレクト、戻る・進むボタン、通常の URL 読み込み) を知るために使用します。

if (window.performance.navigation.type === 0/* TYPE_NAVIGATE */) {
  // 初期表示
} else if (window.performance.navigation.type === 1/* TYPE_RELOAD */) {
  // リロード
} else if (window.performance.navigation.type === 2/* TYPE_BACK_FORWARD */) {
  // 履歴から遷移
} else {
  // その他
}

サンプル

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9