JS: Forward to a site with random parts in the URL


JS: Forward to a site with random parts in the URL



by opening a HTML-site, I want to redirect to the following page:



www.xyz.de?user=default&f1=OPTION1&f2=OPTION2&f3=OPTION3&f4=OPTION4&f5=OPTION5&... etc.



The value for the "OPTIONS" should be randomly selected from a list (array) for every OPTION (1,2,3,4,5,..).



How can I do this with Javascript?



kind regards





is the problem to redirect or to generate the string?
– Nina Scholz
Jun 30 at 18:25




1 Answer
1



Hopefully this will help you, you didn't provide much details or a demo code, so this is from my point of understanding only.


<p id="Link">Link Here</p>
<p id="randoms">Randomly Sortde Array</p>
<script>
var options = ["OPTION1", "OPTION2", "OPTION3", "OPTION4", "OPTION5"]; // Our main array of options
options.sort(function(a, b){return 0.5 - Math.random()}); // We reorder the elements randomly, using : function(a, b){return 1 - Math.random()} will give us the reversed array.
document.getElementById("randoms").innerHTML = options; // Our "randmoly" sorted array
document.getElementById("Link").innerHTML = "www.xyz.de/?user=default&f1="+options[0]+"&f2="+options[1]+"&f3="+options[2]+"&f4="+options[3]+"&f5="+options[4]; // Our Final Link
</script>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

List of Kim Possible characters

Audio Livestreaming with Python & Flask

NSwag: Generate C# Client from multiple Versions of an API