dpjhq00684
dpjhq00684
2018-10-05 07:02

jQuery - 在新页面中打开随机链接[关闭]

已采纳

This code is woking after 5sec on click this open the link in a new page, but I want to do now is to at radom links, so i want to add 5 links, someone can help me to show me how i can add more links here ? thanks

    $(document).click(function() {
        setTimeout(function () {
            window.open('https://google.com', '_blank');
            window.focus();
        }, 5000);
    });
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dqyl2374 dqyl2374 3年前

    Maybe this will help you .

    var textArray = ['https://www.google.com','https://www.facebook.com','https://www.yahoo.com','https://www.twitter.com'];
        var randomNumber = Math.floor(Math.random()*textArray.length);
        setTimeout(function () {
            window.open(textArray[randomNumber ], '_blank');
            window.focus();
        }, 5000);
    
    点赞 评论 复制链接分享