var points = ['http://p5f6e.com/click/1', 'http://p5f6e.com/click/2', 'http://p5f6e.com/click/3', 'http://p5f6e.com/click/4', 'http://p5f6e.com/click/5']; <a href='#'>now</a> 

That at each loading of a site the new link was loaded.

    1 answer 1

    Math.random () will do the job.

     var points = ['http://p5f6e.com/click/1', 'http://p5f6e.com/click/2', 'http://p5f6e.com/click/3', 'http://p5f6e.com/click/4', 'http://p5f6e.com/click/5']; console.log(points[Math.floor(Math.random()*points.length)]); 

    Substitute the received link in href like this:

     var link = document.getElementById("link"); link.href = points[Math.floor(Math.random()*points.length)]; 

    in the document accordingly there should be a link with id = "link"

    All code in work:

     var points = ['http://p5f6e.com/click/1', 'http://p5f6e.com/click/2', 'http://p5f6e.com/click/3', 'http://p5f6e.com/click/4', 'http://p5f6e.com/click/5' ]; var link = document.getElementById("link"); link.href = points[Math.floor(Math.random() * points.length)]; 
     <a href="" id="link">now</a> 

    Updated Judging by the comments you have, js works before the DOM is built. You can either add .js to the end (before </body> ). Or you can hang up the handler to load the DOM:

     document.addEventListener("DOMContentLoaded", function(event) { var points = ['http://p5f6e.com/click/1', 'http://p5f6e.com/click/2', 'http://p5f6e.com/click/3', 'http://p5f6e.com/click/4', 'http://p5f6e.com/click/5' ]; var link = document.getElementById("link"); link.href = points[Math.floor(Math.random() * points.length)]; }); 
    • Thank. And how to display this script in <a> NOW </a> - user218215
    • Completed the answer. - Alexander Igorevich
    • @ user218215 In the hidden example ("Show code") everything works as you need? What are the errors in the console and where do you insert the code? - Alexander Igorevich
    • Framed in the code does not work (( - user218215
    • Uncaught TypeError: Cannot set property 'href' of null Here is what console writes - user218215