4 ms·
Ask HN: How do you do domain randomization for a given web element?
I want to rotate the domain name in a random way. Do you folks know the best way to set the "src" attribute in such a way this can be accomplished?
In other words instead of src=x.foo.com I want to say some <random_str>.foo.com ?
- schappim 8y agofunction makeid() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < 5; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } console.log(makeid()); var randomDomain = makeid() + '.foo.com'; document.getElementsByTagName("object")[0].setAttribute("src", randomDomain);