admin管理员组文章数量:1386543
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; ?>
版权声明:本文标题:javascript - How to automatically reload page after a certain time based on a php variable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744494244a2608920.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论