SOURCE

console 命令行工具 X clear

                    
>
console
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>随机顺序循环跳转页面示例</title>
  <script>
    // 定义链接数组
    var links = [
      'https://example.com/link1',
      'https://example.com/link2',
      'https://example.com/link3',
      'https://example.com/link4',
      // 添加更多链接...
    ];

    // 用于记录已经跳转的链接索引
    var visitedIndices = [];

    function openRandomLink() {
      // 如果已访问数组等于总数组长度,重新统计已访问数组
      if (visitedIndices.length === links.length) {
        visitedIndices = [];
      }

      // 生成一个未访问过的随机索引
      var randomIndex;
      do {
        randomIndex = Math.floor(Math.random() * links.length);
      } while (visitedIndices.includes(randomIndex));

      // 使用 window.open 打开随机链接
      window.open(links[randomIndex], '_blank');

      // 记录已经跳转的链接索引
      visitedIndices.push(randomIndex);
    }
  </script>
</head>
<body>
  <h1>随机顺序循环跳转页面示例</h1>
  <button onclick="openRandomLink()">打开随机链接</button>
</body>
</html>