onload redirect aleatorio

Asked

Viewed 270 times

0

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

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

Is there anything you can do using JS? I believe so but I don’t even know where to start.

Thanks in advance for any help.

  • Can you explain better "activated by onload inside the body tag"? Want a random automatic redirect? or by clicking on a link that has a random address?

  • Without click, I would like it to be automatic.

  • 1

    Do you understand the implications for the user of going to one page and being redirected to another in the browser? That’s bad and the search engines don’t like it... You can’t redirect on the server?

  • Actually I’m trying to create a home page that opens random links every time I open the browser. links would be of pages with messages and frazes of the day of a specific site

  • I agree with Sergio, that this is the kind of pages that I avoid at all costs, where I’m on one page suddenly I’m magically taken to another at random.

  • As I said above, the page itself will not be published, it will be stored locally on my Pc, it will be used as a home page. only the links will be online. theoretically I agree that it is quite annoying, but in this case how the redirect is for personal use I see no problem

  • You can do this by also displaying a section of the page with random information. Then that page could come as a iframe with random page or defined on the server

Show 2 more comments

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?

  • Exactly what I needed, simpler than I imagined, but I could never do it alone. Thank you very much

  • You are welcome, js is very simple even recommend watching videos from Rough-hewn on youtube to learn more about js, Angularjs and nodejs

  • I will watch the videos yes, thank you very much for the help and the tip

Browser other questions tagged

You are not signed in. Login or sign up in order to post.