【问题标题】:Open multiple links, in random order, by clicking one link通过单击一个链接以随机顺序打开多个链接
【发布时间】:2018-04-27 13:22:50
【问题描述】:

(适用于需要焦点小组测试功能的客户)

我正在尝试创建一个链接,单击该链接将打开三个标签页,指向三个不同的网址 - 每次都是随机顺序。

所以“点击我”会以随机顺序同时在三个选项卡中打开 example.com、google.com、facebook。所以第一次点击它可能是 example.com、google.com、facebook.com - 下一次点击可能是 google.com、facebook.com、example 等等。

到目前为止,我有这段代码,它选择一个随机链接,但只选择其中一个 - 我想一次打开所有三个,但顺序是随机的

<script type="text/javascript">
    var urls = [
        "http://example.com",
        'http://google.com',
        'http://facebook.com'
    ];

    function goSomewhere() {
        var url = urls[Math.floor(Math.random()*urls.length)];
        window.location = url; // redirect
    }
</script>

<a href="#" onClick="goSomewhere(); return false;">Start</a>

【问题讨论】:

  • @shyammakwana.me 不,这适用于需要在焦点小组测试中使用它的客户。所以不会被用于任何险恶的事情:-)

标签: javascript random hyperlink tabs


【解决方案1】:
function goSomewhere() {
 while(urls.length)
    window.open(...urls.splice(Math.floor(Math.random()*urls.length),1),"Test");
}

【讨论】:

  • 感谢您的回答!但是您的解决方案仍然只打开一个链接,而不是同时打开所有三个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-17
  • 1970-01-01
  • 1970-01-01
  • 2018-04-03
  • 1970-01-01
  • 2018-10-17
相关资源
最近更新 更多