I currently have a php file that automatically plays the song at the top of a playlist. I have a $duration
value that I pull from a mysql database and I want the page to automatically refresh after the song is finished playing.
The song is currently played within an iframe so this is the only way to tell that the song has approximately finished.
I've tried doing this in javascript but I'm having issues trying to pass a variable to the timeout period.
<script type="text/JavaScript">
function timedRefresh(timeoutPeriod{
setTimeout("location.reload(true);",timeoutPeriod);
}
</script>
<body onload="JavaScript:timedRefresh($x);">
...
</body>
I currently have a php file that automatically plays the song at the top of a playlist. I have a $duration
value that I pull from a mysql database and I want the page to automatically refresh after the song is finished playing.
The song is currently played within an iframe so this is the only way to tell that the song has approximately finished.
I've tried doing this in javascript but I'm having issues trying to pass a variable to the timeout period.
<script type="text/JavaScript">
function timedRefresh(timeoutPeriod{
setTimeout("location.reload(true);",timeoutPeriod);
}
</script>
<body onload="JavaScript:timedRefresh($x);">
...
</body>
Share
Improve this question
edited Dec 6, 2012 at 4:53
Matt Clark
28.6k20 gold badges77 silver badges125 bronze badges
asked Dec 6, 2012 at 4:38
user448948user448948
11 silver badge3 bronze badges
1
- codeforbrowser./blog/lesser-known-facts-about-html – defau1t Commented Dec 6, 2012 at 4:44
2 Answers
Reset to default 3It is simply a straightforward PHP variable output into the source:
<script type="text/JavaScript">
<!--
function timedRefresh(timeoutPeriod){
setTimeout("location.reload(true);",<?php echo $song_duration_in_milliseconds; ?>);
}
</script>
Or use meta-refresh as pointed out in @Matt Clark's answer.
You can also use a META tag for refresh.
In PHP:
<?php
$Refresh = 600;
?>
And in your HTML head you can modify a META Tag:
<meta http-equiv="refresh" content="<?= $Refresh ?>">
Or as stated by Amadan you can just use the PHP to specify the meta tag in your PHP:
header("Refresh: " . $Refresh);
Or In Javascript:
<script type="text/JavaScript">
setTimeout("location.reload(true);",<?= $Refresh ?>);
</script>
Side Notes
The short tags:
<?= $Variable, $Variable2 ?>
Are the equivalent of using:
<?php echo $Variable; echo $Variable2; ?>