how to make such a thing in javascripte + php

<script> function fight(){ <?php if($row['fight'] == 1){ echo "setTimeout(function(){ location.href=''; }, 1000);"; } else{ } ?> } </script> 
  • So here it is made, not? O.O. - ling
  • it just doesn't work on Opera = ( - oOKomarOo
  • Why is location.href = '' going nowhere? Put the anchor - '#' - andy
  • So either you have $row['fight'] != 1 , or change the location.href=''; for something more real. Or at location.reload(); . - ling
  • either the fight () function is simply not called, but rather bring all the code - nosf

2 answers 2

I would do this:

 <script> if ( '<?=$row['fight']?>' == 1 ) fight = Function.prototype; else { fight = function (){ setTimeout( function(){ location.href=''; }, 1000); } } </script> 

But rather:

 <script> fightFlag = <?=( $row['fight'] != 1 )?>; fight = ( fightFlag ? Function.prototype : function (){ setTimeout( "location.href = '';", 1000); } ); </script> 
     <script> function fight(){ if (<?php echo $row['fight']; ?> == 1 { setTimeout(function(){ document.location='/'; }, 1000); } } </script> 
    • offtopic: guessing on the coffee grounds? :) - Alex Kapustin