Random Link Button
Feeling lucky? This script randomly selects a destination from a list you provide, perfect for webrings, random article generators, or surprise content.
Where will you go next?
Copy the Script
<script>
function randomLink() {
var links = [
"http://www.google.com",
"http://www.yahoo.com",
"http://www.bing.com",
"http://www.wikipedia.org"
];
var randIdx = Math.floor(Math.random() * links.length);
window.location = links[randIdx];
}
</script>
<button onclick="randomLink()">Surprise Me!</button>
Frequently Asked Questions
Yes. Simply populate the array with URLs to your blog posts (`/post-1`, `/post-2`, etc.), and the button will act as a 'StumbleUpon' feature for your own content.
Yes, this basic version is truly random, so it might pick the same link twice. To prevent this, you would need to store visited links in a cookie or session storage.
There is no practical limit. JavaScript arrays can hold thousands of strings without performance issues.