Page 1 of 1

simple js to php conversion

Posted: Sat Aug 23, 2008 6:16 pm
by alt303
Hello all. I need some help with converting this javascript to php.

Code: Select all

 
var unknownlinks=new Array()
 
unknownlinks[0]="http://google.com"
unknownlinks[1]="http://yahoo.com"
 
function unknownlink(){
parent.main.window.location=unknownlinks[Math.floor(Math.random()*unknownlinks.length)]
}
 
When this button is clicked it shows a random link in the iframe called "main":

Code: Select all

 
<input type="button" name="button" value="button" onclick="unknownlink()">
 
Any simple way to eliminate the javascript and get the exact functionality with php code? Thanks a lot.

Re: simple js to php conversion

Posted: Sat Aug 23, 2008 9:02 pm
by it2051229
parent.main.window.location <--- there's no PHP conversion for this. That means that the JS code cannot be fully converted into PHP but some parts only...

Re: simple js to php conversion

Posted: Sat Aug 23, 2008 9:26 pm
by alt303
Thanks for the info. Is there no alternative ?

Re: simple js to php conversion

Posted: Sun Aug 24, 2008 1:23 am
by it2051229
for plain full php code.. nope.. but mixture of php and js is possible.. try some experiments and from there you will know how..

Re: simple js to php conversion

Posted: Sun Aug 24, 2008 6:31 am
by Eran
It's quite possible by submitting a form into a php script which sends redirect headers.

Re: simple js to php conversion

Posted: Mon Aug 25, 2008 1:57 am
by Ziq

Code: Select all

 
<?php
if (!empty($_GET['go']))
{
    $unknownlinks[0]="http://google.com";
    $unknownlinks[1]="http://yahoo.com";
     
    header('Location: '.$unknownlinks[rand(0, count($unknownlinks) - 1)]);
}
?>
<form action="<?=$_SERVER['SCRIPT_NAME']?>">
<input type="submit" name="go" value="go">
</form>