onload random redirect

0

I would like to create a function that loads a random page from a particular address. Something like www.meusite.com/(numeros entre 0-100).html

I think the function should create the tag A , then fill it with the text www.meusite.com/ + random number + .html ; and in the end be enabled by onload within tag body .

Can you do something like this using JS? I think so, but I do not even know where to start.

Thank you in advance for any help.

    
asked by anonymous 14.09.2017 / 12:14

1 answer

0

In HTML insert an onload that calls a function:

 <body onLoad="mudarPagina()">

JavaScript Function:

 function mudarPagina() {
      var random = Math.floor((Math.random() * 100) + 1);
      location.href="http://www.meusite.com/"+random+".html";
 }

Would that be?

    
14.09.2017 / 13:43