t4y3
12/11/2017 - 10:18 AM

ページ読み込み種類の判別

ページ読み込み種類の判別

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>ページ読み込み種類の判別</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.3.0/milligram.min.css">
  </head>
  <body>
    <h1>下層ページ</h1>
    <script type="text/javascript">
      document.open();
      if (window.performance.navigation.type === 0/* TYPE_NAVIGATE */) {
        document.write('<h2>読み込み種類:お初</h2>');
      } else if (window.performance.navigation.type === 1/* TYPE_RELOAD */) {
        document.write('<h2>読み込み種類:リロード</h2>');
      } else if (window.performance.navigation.type === 2/* TYPE_BACK_FORWARD */) {
        document.write('<h2>読み込み種類:履歴たどってる</h2>');
      } else {
        document.write('<h2>読み込み種類:その他</h2>');
      }
      document.close();
    </script>
    <a href="./index.html">トップページへ</a>
  </body>
</html>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>ページ読み込み種類の判別</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.3.0/milligram.min.css">
  </head>
  <body>
    <h1>トップページ</h1>
    <script type="text/javascript">
      document.open();
      if (window.performance.navigation.type === 0/* TYPE_NAVIGATE */) {
        document.write('<h2>読み込み種類:お初</h2>');
      } else if (window.performance.navigation.type === 1/* TYPE_RELOAD */) {
        document.write('<h2>読み込み種類:リロード</h2>');
      } else if (window.performance.navigation.type === 2/* TYPE_BACK_FORWARD */) {
        document.write('<h2>読み込み種類:履歴たどってる</h2>');
      } else {
        document.write('<h2>読み込み種類:その他</h2>');
      }
      document.close();
    </script>
    <a href="./index2.html">下層ページへ</a>
  </body>
</html>

ページ読み込み種類の判別