[英]JavaScript page reload timer with alert
What I am trying to do is after 59 minutes reload the page and after the page is reload display a message stating that the page has been reload. 我要执行的操作是在59分钟后重新加载页面,并在页面重新加载后显示一条消息,指出该页面已被重新加载。 Then set the timer again and repeat the same thing.
然后再次设置计时器并重复相同的操作。 I am having trouble with hiding and displaying the alert and also a little lost on the logic after the first refresh.
我在隐藏和显示警报时遇到了麻烦,并且在第一次刷新后在逻辑上也有些失落。 This is what I have so far:
这是我到目前为止的内容:
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.Bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jQuery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<script language="JavaScript"> <!--
function checkRefresh()
{
if( document.refreshForm.visited.value == "" )
{
// This is a fresh page load
document.refreshForm.visited.value = "1";
document.getElementById(a).style.visibility="hidden";
window.setTimeout(myalertfunction, 59 * 60 * 1000)
}
else
{
document.getElementById(a).style.visibility="visible";
// This is a page refresh
window.setTimeout(myalertfunction, 59 * 60 * 1000)
}
} -->
</script>
</head>
<body onLoad="JavaScript:checkRefresh();">
<div class="alert alert-info fade in" id="a">
<a href="#" "class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Info!</strong> This Page has been reloaded!
</div>
<form name="refreshForm">
<input type="hidden" name="visited" value="" />
</form>
</body>
</html>
Try using <meta>
tag 尝试使用
<meta>
标签
<meta http-equiv="refresh" content="5; URL=http://www.example.com/test.html">
OR JavaScript's setTimeout()
或JavaScript的
setTimeout()
setTimeout(function(){
window.location.reload(1);
},60000)
Maybe you can try something like this : 也许您可以尝试这样的事情:
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.Bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<script language="JavaScript">
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$(document).ready(function() {
var visitedValue = getParameterByName('visited',window.location.href);
if (visitedValue === '1') {
$('#a').show();
}
setTimeout(function(){
$('#visited').val('1');
$('#refreshForm').action = window.location.href;
$('#refreshForm').submit();
},3540000);
});
</script>
</head>
<body>
<div class="alert alert-info fade in" id="a" style="display:none;">
<a href="#" "class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Info!</strong> This Page has been reloaded!
</div>
<form name="refreshForm" id="refreshForm">
<input type="hidden" id="visited" name="visited" value="" />
</form>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.