ラボ > Javascript関連:イベント関連
js 「ブラウザバックで戻ってきた」ときの制御(performance.getEntriesByType())
「ブラウザバックで戻ってきた」だけなのか、それを知りたい
作成日:2021-10-20, 更新日:2021-10-27
基本
▼「performance.getEntriesByType()」で取得する
performance.getEntriesByType('navigation');
※「performance.navigation.type」は非推奨らしい・・・
サンプル
「performance.getEntriesByType()」は配列で返ってくるので、ループさせる必要がある
var performance_entries = performance.getEntriesByType('navigation');
performance_entries.forEach(function(pe){
switch( pe.type ){
case 'navigate': /* 通常のアクセス */ break;
case 'reload': /* リロード */ break;
case 'back_forward': /* ブラウザバック */ break;
case 'prerender': /* レンダリング前 */ break;
}
});