Is there a way to make an action available only at a specific time that was programmed in advance in HTML?
For example: A radio player that will only work at a certain time and at other times the link is not active
Is there a way to make an action available only at a specific time that was programmed in advance in HTML?
For example: A radio player that will only work at a certain time and at other times the link is not active
Yes, it is possible using JavaScript. Look at functions setTimeout
or setInterval
. You can find an example here - Call a javascript function at a specific time of day .
If for some reason you cannot use JavaScrip, another option would be to use some server-side technology (PHP, ASP.Net) to modify the html before the response is returned to the browser. In this case, the back-end should check if the current time is valid to let the user click the link and modify the Html markup such that e. g. a link would be clickable or not.
Yes, use javascript to do this. Many ways:
<script>
function is_active() {
if (/* working at this time */) return true;
else return false;
}
</script>
<a href="..." onClick="return is_active();">...</a>
This is probably the easiest way, as long as the functionality is controlled by a link
<div style="position:relative;">
player here - including links to start/stop
<div id="overlaydiv"
style="position: absolute; left: 0; top: 0; width: 100%; height: 100%;
opacity: 50%; background-color: white;"> </div>
</div>
<script>
setTimeout(function () {
$(overlaydiv).css("display: block;")
},milliseconds until inactive);
</script>
If you use javascript to get the local time on the user's computer, be aware that a user may MANIPULATE their clock. So you may not be able to trust it.
You can mitigate this risk by getting the server to save the actual time in a javascript variable on page load. However, the user can still manipulate their clock if you are using timers to find the time change.
If it is important, you should probably do an AJAX request to check the server time before allowing a link click to start the player (eg. with the 1st method).