Javascript onload/onblur, opening one link randomly?
I'm looking for something like the code below, but it should randomly pick one link (or would it work with iframed videos inside as well?) to load whenever the side is refreshed and/or blurred.
How can this be randomized?
<script>
window.onblur = function() {开发者_Go百科
TIMER = setTimeout(changeItUp, 5000);
}
window.onfocus = function() {
if (TIMER) clearTimeout(TIMER);
}
function changeItUp() {
location.href = "http://www.yahoo.com"
}
</script>
//return a random number between 0 and 1
document.write(Math.random() + "<br />");
//return a random integer between 0 and 10
document.write(Math.floor(Math.random()*11));
Then just have an array with your links and select a random one
linkArray[Math.floor(Math.random()*11)]
very basic stuff though, you should google for things like this.
精彩评论