0

ここに私のスクリプトがあります。これはphpとjavascriptを組み合わせたものです

<?php
$countdown = strtotime("22:00") - time();
$itemtime = "22:00";
$realtime = substr(date('H:i'),0,5);
?>

<script>
var itemtime = "$itemtime";
var countdown = '$countdown';
var url = "$redirectpage";
var realtime = "$realtime";

// HOW WILL I ADD AN IF STATEMENT WITH THE SETTIMEOUT FUNCTION
// WHEREBY, if(realtime == itemtime) ..that's the only time the 
// redirection should occur

setTimeout(function(){
 location.href='$redirectpage'; 
    },countdown * 1000);

</script>
4

2 に答える 2

2
<?php
$countdown = strtotime("22:00") - time();
$itemtime = "22:00";
$realtime = substr(date('H:i'),0,5);
?>

<script>
var itemtime = "<?php echo $itemtime;?>";
var countdown = '<?php echo $countdown;?>';
var url = "$redirectpage";
var realtime = "<?php echo $realtime;?>";

// HOW WILL I ADD AN IF STATEMENT WITH THE SETTIMEOUT FUNCTION
// WHEREBY, if(realtime == itemtime) ..that's the only time the 
// redirection should occur

setTimeout(function(){
 if(realtime == itemtime) location.href='$redirectpage'; 
},countdown * 1000);
</script>

Assuming $redirectpage is set in JavaScript and not PHP. If it is set in PHP, you'll need to assign it as I did above.

于 2013-01-10T14:24:30.880 に答える
0

私は自分の解決策になりました。これを setTimeout 関数内に配置します

if(countdown < 0) setTimeout("location.reload(true);",1000); location.href= "$redirectpage";
于 2013-01-11T03:02:42.960 に答える