Open random page in lightbox (colorbox)
How can I make a link open a random page from a list of pages in a colorbox lightbox based on the following code:
<a class="colorbox" href="page1.html"...
==========UPDATE==========
Thanks Tomm...
I edited your code as follows:
$(document).ready(function() {
$("a.random").click(function() {
var randomnumber = Math.floor(Math.random()*8+1);
if (randomnumber == '1'){
$(this).attr("href","anypageiwant.html");
}
else if....
However, sometimes the same random number/page is chosen more than开发者_如何学运维 once. Is there any way to avoid this?
$(document).ready(function() {
$("a.colorbox").click(function() {
$(this).attr("href","print"+Math.floor(Math.random()*11)+".html");
});
});
Just replace the 11 with whatever number of pages you've got plus 1 (i.e. if you have page1.html to page15.html use Math.random()*16).
精彩评论