I have a script which creates an element of iframe. I have a button which refreshes the iframe link.
I need to do something to change a variable in the iframe src on every click of the button.
I'll explain the real issue. I have a list of games I have with random name like,
boomer.swf, kingdom.swf, balloon.swf and so on.
So I somehow made this,
Code:
var r_text = new Array ();
r_text[0] = "boomer";
r_text[1] = "kingdom";
r_text[2] = "balloon";
var i = Math.floor(3*Math.random())
var gamedrome = { game: ""+r_text[i]+""};
Now I have a .js file which creates iframe element
Code:
function embed_game(params, options)
{
var data = [];
for(var i in params)
{
data.push(i + "=" + encodeURIComponent(params[i]));
}
data = data.join("&");
var frame = document.createElement("iframe");
frame.src = "http://website.com/embed/game.html?"+ data;
frame.style.width="100%";
frame.style.height="100%";
frame.style.border = "0";
frame.frameBorder = "0";
frame.id="newroom";
....
and another small script to refresh the inner iframe and not the page to change game.
Code:
<script type="text/javascript">
function Reload () {
var f = document.getElementById('newroom');
f.src = f.src;
}
</script>
It all works fine until the game is loaded, but the problem is that if once the game is loaded in site, the iframe source is already set and my button keeps loading the same game. I need to randomize it on every click. Please help me out.