如何创建随机链接到多个网站的按钮? [英] How Can I Create a Button that links to multiple websites randomly?
问题描述
我只是想知道如何创建一个按钮,每次点击它时,可以按随机顺序将人带到多个网站。我不希望这些网站一次打开,一次只能打开一个。我正在寻找类似于StumbleUpon上使用的绊倒按钮的东西。我打算将这个按钮用于我计划创建的工具栏,所以如果有人在这里可以回答这个问题,我会非常感激。谢谢!
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!
推荐答案
创建一个包含目标网址的JS数组,并在点击按钮时从中随机选择。
Make a JS array with the target URLs, and randomly pick from it when the button is clicked.
这是一个有效的例子:
<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>
此处是指定此onClick处理程序的链接。
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.
仅供参考疯狂链接来自 TheUselessWeb的列表。
Just FYI the crazy links come from TheUselessWeb's list.
这篇关于如何创建随机链接到多个网站的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!