mercredi 11 septembre 2019

Load random page in iframe when page loads [duplicate]

This question already has an answer here:

I'm trying to work on different ad placements on a website. I need an iframe to load an entire page on a single URL, but I need it to pick a URL randomly from a list.

I cannot get the iframe to show anything using my id function. It just ends up blank.

<style type="text/css">
   body {scrolling:no;}
   iframe {position:absolute;
   z-index:1;
   top:100px;
   left:100px;}
</style>
</head>

<br>

<script type="text/javascript">
    var cat1 = [
    "http://www.google.com"
    ];

var myFrame = document.getElementById("random");

function getRandomUrl(myFrame) {
    var index = Math.floor(Math.random()*cat1.length);
    var url = cat1[index];
        myFrame.src = url;
    }
    window.onload = function(){
    getRandomUrl(myFrame); 
});
</script>
<iframe id="random" src="" style="width:500px; height: 500px"></iframe>




Aucun commentaire:

Enregistrer un commentaire