How Can I Create a Button that links to multiple websites randomly?

后端 未结 1 1896
长情又很酷
长情又很酷 2021-01-29 09:49

I just wanted to know how can I create a button that can take a person to multiple websites in a random order when it is clicked each time. I do not want these websites to open

相关标签:
1条回答
  • 2021-01-29 10:31

    Make a JS array with the target URLs, and randomly pick from it when the button is clicked.

    Here is a working example:

    <script type="text/javascript">
        var urls = [
            "http://www.kittenwar.com/",
            'http://heeeeeeeey.com/',
            'http://eelslap.com/',
            'http://www.staggeringbeauty.com/',
            'http://www.omfgdogs.com/',
            'http://burymewithmymoney.com/',
            'http://www.fallingfalling.com/',
            'http://ducksarethebest.com/',
            'http://www.republiquedesmangues.fr/',
            'http://www.trypap.com/',
            'http://www.hristu.net/',
            'http://www.partridgegetslucky.com/',
            'http://www.rrrgggbbb.com/',
            'http://www.sanger.dk/',
            'http://www.geodu.de/',
            'http://beesbeesbees.com/',
            'http://breakglasstosoundalarm.com/',
            'http://www.koalastothemax.com/',
            'http://grandpanoclothes.com/',
            'http://www.everydayim.com/',
            'http://www.haneke.net/',
            'http://instantostrich.com/',
            'http://r33b.net/',
            'http://cat-bounce.com/'
        ];
    
        function goSomewhere() {
            var url = urls[Math.floor(Math.random()*urls.length)];
            window.location = url; // redirect
        }
    </script>
    

    And here is a link with this onClick handler assigned.

    <a href="#" onClick="goSomewhere(); return false;">Gimme something weird!</a>
    

    You can style it to look like a button, if you want.


    Just FYI the crazy links come from TheUselessWeb's list.

    0 讨论(0)
提交回复
热议问题