Created
March 14, 2014 18:39
-
-
Save yanknudtskov/9553986 to your computer and use it in GitHub Desktop.
Redirect to random page using JS and jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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