link randon using iframe

0

I have this code below and I need the link inside the iframe to change every refresh of the page and I did it as below only that it did not work only works with clickable link ... like this in the code

    <html>
<head>
    <title>Link Aleatorio</title>
<script>
    var enderecos = new Array("http://www.terra.com.br", "http://www.google.com.br", "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>
    
asked by anonymous 25.02.2017 / 23:01

1 answer

1

Example at ideone

Note: If you return a blank page, the site does not allow it to be displayed in an 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 to be displayed in iframe (google, yahoo, oglobo etc ...)

    
27.02.2017 / 00:51