
Ask HN: How do you do domain randomization for a given web element? - dedalus
I want to rotate the domain name in a random way. Do you folks know the best way to set the &quot;src&quot; attribute in such a way this can be accomplished?<p>In other words instead of src=x.foo.com I want to say some &lt;random_str&gt;.foo.com ?
======
schappim

      function 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);

