Javascript HTML-检查日期/时间,但仅在工作时间刷新页面
下面的脚本运行良好,但我希望添加刷新index.htm页面的功能,作为脚本的一部分,而不是元刷新标记。我的“开放”时间是周一到周五,上午8点到下午5点 页面加载后,它每1分钟刷新一次,但我希望它仅在“打开”时间内每分钟刷新一次,而不是在“打开”时间之外。但是,如果访问者在周一上午7:59打开index.htm页面,那么应该有一种方法在上午8:00时强制重新加载页面。谢谢你的帮助Javascript HTML-检查日期/时间,但仅在工作时间刷新页面,javascript,html,onload,Javascript,Html,Onload,下面的脚本运行良好,但我希望添加刷新index.htm页面的功能,作为脚本的一部分,而不是元刷新标记。我的“开放”时间是周一到周五,上午8点到下午5点 页面加载后,它每1分钟刷新一次,但我希望它仅在“打开”时间内每分钟刷新一次,而不是在“打开”时间之外。但是,如果访问者在周一上午7:59打开index.htm页面,那么应该有一种方法在上午8:00时强制重新加载页面。谢谢你的帮助 <meta http-equiv="refresh" content="60;ur
<meta http-equiv="refresh" content="60;url=index.htm">
=======
<script type="text/javascript">
var view = [
'open-menu.png',
'closed-menu.png'
];
onload = function () {
var now = new Date();
var dayofweek = now.getDay();
var HH = now.getHours();
if ( ((HH >= 8) && (HH < 17)) && ((dayofweek >= 1) && (dayofweek <= 5)) ) {
document.getElementById('image').src = view[0];
} else {
document.getElementById('image').src = view[1];
}
}
</script>
========
<body>
<img id="image" src="">
</body>
=======
变量视图=[
“open menu.png”,
'closed menu.png'
];
onload=函数(){
var now=新日期();
var dayofweek=now.getDay();
var HH=now.getHours();
如果((HH>=8)和(&&(HH<17))&((dayofweek>=1)和(&(dayofweek)如果我正确理解了您的要求,请尝试以下方法:
<script type="text/javascript">
var view = [
'open-menu.png',
'closed-menu.png'
];
onload = function () {
var now = new Date();
var dayofweek = now.getDay();
var HH = now.getHours();
if ( ((HH >= 8) && (HH < 17)) && ((dayofweek >= 1) && (dayofweek <= 5)) ) {
document.getElementById('image').src = view[0];
window.setTimeout(function () {
window.location.reload();
}, 60000);
} else {
document.getElementById('image').src = view[1];
}
}
</script>
变量视图=[
“open menu.png”,
'closed menu.png'
];
onload=函数(){
var now=新日期();
var dayofweek=now.getDay();
var HH=now.getHours();
如果在我看来((HH>=8)和(&&(HH<17))&&((dayofweek>=1)和(&(dayofweek)重新加载整个页面不是最好的解决方案,请尝试以下方法:
setInterval(yourFunction, 60000)
谢谢Orassayg,这正是我所需要的,非常感谢!对于在周一7:59打开页面的访问者,我想我需要更多的帮助,来自ΚωνσταντττενΓοςαφη:)很高兴能帮助。请将这个答案标记为已接受,谢谢:)这有效:`` onload=function(){var now=new Date();var dayofweek=now.getDay();var HH=now.getHours();if((HH>=8)和&(HH<17))和&((dayofweek>=1)和&(dayofweek