I'm trying to make a trivia game. Ideally, I have a main webpage containing a button and, on top of the button, an iframe. Clicking the button sends you to a randomized webpage that would contain a question, without ever having to leave the main webpage.
I'm having two problems with my code so far. (1) The button sends my iframe link to my main webpage (i.e. I click the button and I now have my main webpage, with my main webpage again in the iframe), and (2) the button only seems to work on the first click.
Here's my code, thank you!
CODE
<iframe src="/contact" name="A" width="500" height="250"></iframe>
======
<script>
var sites = [
'/capfriendly',
'/capfriendly',
'/capfriendly'
];
function randomSite() {
var i = parseInt(Math.random() * sites.length);
iframe.src= sites[i];
}
</script>
<a href="#" target="A" onclick="randomSite();">BUTTON</a>
======
<script>
var sites = [
'/capfriendly',
'/capfriendly',
'/capfriendly'
];
function randomSite() {
var i = parseInt(Math.random() * sites.length);
iframe.src= sites[i];
}
</script>
<a href="#" target="A" onclick="randomSite();">BUTTON</a>