-1

My code right now is currently this.

As you can see, it generates 2 random strings into places into a link containing both letters and numbers. But how can I force it to open or redirect to that newly generated link? Or even perhaps iFrame it?
Since right now, it just simply writes it out how the link will look after being generated.

By the way, what I am looking for is also here: " How to change part of an iFrame’s URL to a random string? "

I got this far after seeing that.

  function randString(x) {
    var s = "";
    while (s.length < x && x > 0) {
      var r = Math.random();
      s += (r < 0.1 ? Math.floor(r * 100) : String.fromCharCode(Math.floor(r * 26) + (r > 0.5 ? 97 : 65)));
    }
    return s;
  }

document.getElementById("doo").innerHTML = randString(4);

The above is my JavaScript code found on the JSFiddle which I'm using for generating a part of the link.

Community
  • 1
  • 1
Metaton
  • 31
  • 4
  • 1
    I'm so sorry about that. I'm kinda beginner in these things... Nathangrad made a edit for it. Thanks for him. – Metaton Dec 09 '15 at 11:40

1 Answers1

1

Super simple stuff.. For now, you're just putting your generated link string into a dummy element's innerHTML called "doo" (which is not available in your code snippet above, causing that you see no output when you run the snippet)

now, you want to open this link? or iframe it? easy..

var myLink = 'http://anylink.com/' + randString(4);
window.open(myLink); // this will open the link in a new window/tab

or an iframe would be like this

var myLink = 'http://anylink.com/' + randString(4);
var myIframe = document.createElement('iframe');
myIframe.src = myLink;
document.body.appendChild(myIframe);

é voilà :)

oh and if you want to "rotate" your iframe - this would be a CSS task - a CSS definition for the iframe like this for example:

iframe {
  transform: rotateZ(45deg);
}
jebbie
  • 1,418
  • 3
  • 17
  • 27