trying to make a iframe with a random youtube links at page upload without any onclick
var glink = 0;
var games = new Array();
games[glink++] = "http://www.youtube.com/pRpvdcjkT3k";
games[glink++] = "http://www.youtube.com/Te4wx4jtiEA";
function randomglink() {
var random = rand(glink) - 1;
location.src = games[random];
}
<div><iframe width="283" height="242.5" src="randomglink()" frameborder="0" allowfullscreen></iframe></div>
The
src
attribute is not like an event (e.g.onclick
) that executes a javascript function to get its location/URL. But you can dynamically change the src attribute.To have a script triggered on page load (without jQuery etc.)
In order to manipulate your
iframe
element, give it anid
(has to be unique). In this example I named itvideoFrame
:Then from your script, set the
src
attribute:this help you :