link Randon using iframe

Asked

Viewed 164 times

-1

I have this code below and I need the link inside the iframe to change every refresh of the page and I did the following way below only that it does not function only with clickable link... as this in the code

    <html>
<head>
    <title>Link Aleatorio</title>
<script>
    var enderecos = new Array("http://www.terra.com.br", "http://www.google.com", "http://jbonline.terra.com.br", "http://www.lycos.com", "http://br.yahoo.com", "http://www.altavista.com", "http://www.hotbot.com", "http://www.buscopio.com", "http://oglobo.globo.com", "http://www.excite.com", "http://br.cade.yahoo.com", "http://www.mercadolivre.com.br", "http://br.weather.com", "http://www.buscape.com.br", "http://www.msn.com", "http://www.astrolabio.net")
    function linkAleatorio(){
       aleat = Math.random() * enderecos.length
       aleat = Math.floor(aleat)
       window.location=enderecos[aleat]
    }
</script>
</head>

<body>
<!--<a href="javascript:linkAleatorio()">LinkAleatorio</a>-->
<iframe src="<?php echo javascript:linkAleatorio(); ?>" width="100%" height="100%" frameborder="0"  scrolling="yes" allowfullscreen></iframe>
</body>
</html>

1 answer

0


Example in ideone

Obs: if return blank page is because the site does not allow it to be displayed in iframe.

Since your tag has PHP do so:

<?php
$enderecos = array("http://www.terra.com.br", "http://jbonline.terra.com.br", "http://www.lycos.com", 
"http://www.hotbot.com", "http://www.buscopio.com", "http://oglobo.globo.com", "http://www.excite.com", 
"http://br.cade.yahoo.com", "http://www.mercadolivre.com.br", "http://www.buscape.com.br", 
"http://www.astrolabio.net");

$result = (rand(0,count($enderecos)-1));
?>


<iframe src="<?= $enderecos[$result] ?>" width="100%" height="100%" frameborder="0" scrolling="yes" allowfullscreen></iframe>

NOTE: many sites do not allow them to be displayed in iframe (google, yahoo, oglobo etc...)

  • Thank you very much worked as expected.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.