1

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>
  • Aside from the duplicate, you have some misplaced braces and parentheses and should run your JS through a linter / look at the errors in the console of your browser's developer tools. – Quentin Sep 11 '19 at 07:03

0 Answers0