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.
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.
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)]; }); Source: https://ru.stackoverflow.com/questions/558777/
All Articles