Show an element only between specific times
Here is how to show, say an embed or an iframe only at specified time by using an if condition
In this example, we are showing how to display an iframe but that part of the code can be replaced with any element you would like to show
// Specify start time
var startTime = '8:00 AM';
// Specify end time
var endTime = '5:00 PM';
var now = new Date();
var startDate = dateObj(startTime); // get date objects
var endDate = dateObj(endTime);
var flag = now < endDate && now > startDate ? 'showElement' : 'hideElement';
if (flag === 'showElement') {
//alert("showFrame"); // uncomment to test
document.getElementById("row").style.display = "block";
}
// parse the date
function dateObj(d) {
var parts = d.split(/:|\s/),
date = new Date();
if (parts.pop().toLowerCase() == 'pm') parts[0] = (+parts[0]) + 12;
date.setHours(+parts.shift());
date.setMinutes(+parts.shift());
return date;
}
<html>
<head>
<body>
<!-- This will only be shown between 8am to 5pm local time -->
<div class="row">
<iframe src="https://youtube.com/embed"></iframe>
</div>
</body>
</head>
</html>