How Can I Create a Button that links to multiple w

2019-03-07 00:42发布

问题:

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 all at once, only one at a time. I'm looking for something similar to the "stumble" button that is used on StumbleUpon. I plan on using this button for a toolbar that I'm planning to create so if anyone here can answer this question I'd greatly appreciate it. Thanks!

回答1:

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.