0

how do i adding text from js file to src in iframe and wont be the same text in another iframe

var games = new Array ();
games[0] = "mhgxcdufRbE?rel=0&showinfo=0";
games[1] = "jrndhugilod?rel=0&showinfo=0";
games[2] = "oloprokbanse?rel=0&showinfo=0";
games[3] = "nfbeuujshre?rel=0&showinfo=0";
games[4] = "sd54ddsaegdd?rel=0&showinfo=0";
games[5] = "h5gffy73jssa?rel=0&showinfo=0";
games[6] = "ffa87gb3n21s?rel=0&showinfo=0";
var i = Math.floor(7*Math.random())

document.write(games[i]);
<iframe src="https://www.youtube.com/embed/ + games[i]" width="283" height="242.5" frameborder="0" allowfullscreen></iframe>
  • In a script, get a reference to the iframe and assign the value you need to its `src` property. – Teemu Jun 16 '16 at 18:41
  • can you wroth me the code plz – Tomer Shwartz Jun 16 '16 at 18:46
  • https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction – Teemu Jun 16 '16 at 18:49
  • You asked a *very* similar question just a few hours ago which holds the answer to this question: http://stackoverflow.com/questions/37857888/trying-to-random-several-links-youtube-videos-in-iframe-inside-div – mferly Jun 16 '16 at 18:50
  • 1
    Possible duplicate of [Changing iframe src with Javascript](http://stackoverflow.com/questions/3730159/changing-iframe-src-with-javascript) – Kld Jun 16 '16 at 18:55
  • its a different way.. the way that i asked wont fixed to my website – Tomer Shwartz Jun 16 '16 at 19:16

1 Answers1

0

var games = [];
games[0] = "mhgxcdufRbE?rel=0&amp;showinfo=0";
games[1] = "jrndhugilod?rel=0&amp;showinfo=0";
games[2] = "oloprokbanse?rel=0&amp;showinfo=0";
games[3] = "nfbeuujshre?rel=0&amp;showinfo=0";
games[4] = "sd54ddsaegdd?rel=0&amp;showinfo=0";
games[5] = "h5gffy73jssa?rel=0&amp;showinfo=0";
games[6] = "ffa87gb3n21s?rel=0&amp;showinfo=0";

var i = Math.floor( 7 * Math.random() ),
 iFrame = document.getElementById('iFrame').src = 'https://www.youtube.com/embed/' + games[i];
<iframe id="iFrame" src="<INSERT DEFAULT URL HERE?>" width="283" height="242.5" frameborder="0"></iframe>

Also fiddle

Merely setting the <iframe> src with your random URL.

mferly
  • 1,646
  • 1
  • 13
  • 19