Skip to content

Instantly share code, notes, and snippets.

@yanknudtskov
Created March 14, 2014 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanknudtskov/9553986 to your computer and use it in GitHub Desktop.
Save yanknudtskov/9553986 to your computer and use it in GitHub Desktop.
Redirect to random page using JS and jQuery
var urlArray = ['http://url1.com', 'http://url2.com', 'http://url3.com'];
var random_url;
var redirect_after_milliseconds = 2000;
$(function() {
random_url = urlArray[Math.floor(Math.random() * urlArray.length)];
setTimeout(function() {
// similar behavior as an HTTP redirect
window.location.replace(random_url)
}, redirect_after_milliseconds);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment