2016-07-15 13 views
0

FYI, ich bin überhaupt nicht ein Programmierer, so etwas muss klar zu buchstabieren.Random Href mit jquery und colorbox

Ich verwende dieses .js-Skript im Sharepoint. Es funktioniert gut!


<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset=utf-8 /> 
    <title>ColorBox demo</title> 
    <link rel="stylesheet" href="http://www.jacklmoore.com/colorbox/example1/colorbox.css" /> 
    </head> 
    <body> 
    <h1>Hello, there!</h1> 
    <h2>This is some content</h2> 
    <p>The popup will open in five seconds</p> 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
    <script src="http://www.jacklmoore.com/colorbox/jquery.colorbox.js"></script> 
    <script> 
     function openColorBox(){ 
     $.colorbox({iframe:true, width:"40%", height:"30%", href: "http://172.16.96.254/pf17.html"}); 
     } 

     setTimeout(openColorBox, 5000); 
     setTimeout(parent.$.colorbox.close, 15000); 
    </script> 
    </body> 
</html> 

Ich habe auf einem lokalen internen Website mehrere Seiten erstellt. pf1.html - pf21.html

Ich möchte diese zufällig randomize, wenn das Popup ausgeführt wird.

Ich habe diese Funktion gesehen..posted in diesem Forum.

(Math.random() * 11)

Wie kann ich dies auf die obige Skript und die Seiten randomisieren.

Dies ist die vollständige Zufalls Clip

$(document).ready(function() { 
$("a.colorbox").click(function() { 
$(this).attr("href","print"+Math.floor(Math.random()*11)+".html"); 
}); 

ich die * 11 setzt die Anzahl der Seiten wissen ..

Antwort

0

Versuchen Sie so etwas wie:

function openColorBox(){ 
    var urlBase = "http://172.16.96.254/pf"; 
    var urlPage = Math.floor(Math.random() * 21); 
    var urlExt = ".html"; 

    var randomizedURL = urlBase + urlPage + urlExt; 

    $.colorbox({iframe:true, width:"40%", height:"30%", href: randomizedURL}); 
    } 

    setTimeout(openColorBox, 5000); 
    setTimeout(parent.$.colorbox.close, 15000);