如何刷新命名分区而不是整个页面?
How to Refresh A named divison and not the entire page?
我好像不太明白。之前帮助过我的人告诉我使用 jQuery,我已经尝试过但无法让它工作。我正在尝试自动刷新我创建的 html 页面上的一个分区,而不是整个页面。
我尝试了 meta 刷新,但是主页面是这样的。我搜索的每个地方都有类似的答案,但我无法让它工作。我要刷新的分区称为 "Frame" 我只需要它每 45 分钟刷新一次。
<html>
<head>
<title>Station 47</title>
</head>
<body bgcolor="DarkRed">
<body a link="black" vlink="black">
<center><font face="Times New Roman" size="6"><marquee behavior="scroll" direction="left">Naval District Washington Fire Department Station 47</marquee>
</body>
<table border="0">
<tr>
<td>
<p align="left">
<iframe id="Iframe1" src="https://webview.active911.com/client/" frameborder="0" scrolling="no" width="2360" height="930"></iframe>
</td>
</tr>
<tr>
<td>
<div>
<iframe id="Iframe2" src="http://www.chart.state.md.us/video/video.php?feed=7401e25800f700d700437a45351f0214" width="400" height="400" Frameborder="0" scrolling="no"></iframe>
<iframe id="Iframe3" src="http://www.chart.state.md.us/video/video.php?feed=7e01ec5800f700d700437a45351f0214" width="400" height="400" Frameborder="0" scrolling="no"></iframe>
<iframe id="Iframe4" src="http://www.chart.state.md.us/video/video.php?feed=7901e75800f700d700437a45351f0214" width="400" height="400" frameborder="0" scrolling="no"></iframe>
<iframe id="Iframe5" src="http://www.chart.state.md.us/video/video.php?feed=6100bdd12e83001c00503336c4235c0a" width="400" height="400" frameborder="0" scrolling="no"></iframe>
<iframe id="Iframe6" src="http://www.chart.state.md.us/video/video.php?feed=4900c5b02e84001c00503336c4235c0a" width="400" height="400" frameborder="0" scrolling="no"></iframe>
<iframe id="Iframe7" src="http://api.wunderground.com/api/5ce4445b4bd79f9a/animatedradar/q/MD/Annapolis.gif?&width=415&height=415&newmaps=1&timelabel=1&timelabel.y=10&num=15&delay=50" width="338" height="400" frameborder="0" scrolling="no"></iframe></td>
</div>
</td>
</tr>
</table>
</html>
鉴于您的 html 代码是正确的,您可以执行以下操作:
include jquery(在您的头部或页面底部,正文结束标记之前添加以下内容):
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
使用jQuery,编写一个能够获取所有iframe的函数:
function reloadFrames(){
$(".Frames iframe").each(function(i, iframe){
iframe.contentDocument.location.reload(true);
});
}
每 45 分钟调用一次函数。为此,您可以使用 setInterval
。第一个参数是要调用的函数,第二个参数是频率,以毫秒为单位:
setInterval(reloadFrames, 45*60*1000);
回顾一下,您可以在正文末尾粘贴以下内容:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
setInterval(reloadFrames, 1000);
function reloadFrames() {
console.log("reloading iframes")
$(".Frames iframe").each(function(i, iframe) {
iframe.contentDocument.location.reload(true);
});
}
});
</script>
我好像不太明白。之前帮助过我的人告诉我使用 jQuery,我已经尝试过但无法让它工作。我正在尝试自动刷新我创建的 html 页面上的一个分区,而不是整个页面。
我尝试了 meta 刷新,但是主页面是这样的。我搜索的每个地方都有类似的答案,但我无法让它工作。我要刷新的分区称为 "Frame" 我只需要它每 45 分钟刷新一次。
<html>
<head>
<title>Station 47</title>
</head>
<body bgcolor="DarkRed">
<body a link="black" vlink="black">
<center><font face="Times New Roman" size="6"><marquee behavior="scroll" direction="left">Naval District Washington Fire Department Station 47</marquee>
</body>
<table border="0">
<tr>
<td>
<p align="left">
<iframe id="Iframe1" src="https://webview.active911.com/client/" frameborder="0" scrolling="no" width="2360" height="930"></iframe>
</td>
</tr>
<tr>
<td>
<div>
<iframe id="Iframe2" src="http://www.chart.state.md.us/video/video.php?feed=7401e25800f700d700437a45351f0214" width="400" height="400" Frameborder="0" scrolling="no"></iframe>
<iframe id="Iframe3" src="http://www.chart.state.md.us/video/video.php?feed=7e01ec5800f700d700437a45351f0214" width="400" height="400" Frameborder="0" scrolling="no"></iframe>
<iframe id="Iframe4" src="http://www.chart.state.md.us/video/video.php?feed=7901e75800f700d700437a45351f0214" width="400" height="400" frameborder="0" scrolling="no"></iframe>
<iframe id="Iframe5" src="http://www.chart.state.md.us/video/video.php?feed=6100bdd12e83001c00503336c4235c0a" width="400" height="400" frameborder="0" scrolling="no"></iframe>
<iframe id="Iframe6" src="http://www.chart.state.md.us/video/video.php?feed=4900c5b02e84001c00503336c4235c0a" width="400" height="400" frameborder="0" scrolling="no"></iframe>
<iframe id="Iframe7" src="http://api.wunderground.com/api/5ce4445b4bd79f9a/animatedradar/q/MD/Annapolis.gif?&width=415&height=415&newmaps=1&timelabel=1&timelabel.y=10&num=15&delay=50" width="338" height="400" frameborder="0" scrolling="no"></iframe></td>
</div>
</td>
</tr>
</table>
</html>
鉴于您的 html 代码是正确的,您可以执行以下操作:
include jquery(在您的头部或页面底部,正文结束标记之前添加以下内容):
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
使用jQuery,编写一个能够获取所有iframe的函数:
function reloadFrames(){ $(".Frames iframe").each(function(i, iframe){ iframe.contentDocument.location.reload(true); }); }
每 45 分钟调用一次函数。为此,您可以使用
setInterval
。第一个参数是要调用的函数,第二个参数是频率,以毫秒为单位:setInterval(reloadFrames, 45*60*1000);
回顾一下,您可以在正文末尾粘贴以下内容:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
setInterval(reloadFrames, 1000);
function reloadFrames() {
console.log("reloading iframes")
$(".Frames iframe").each(function(i, iframe) {
iframe.contentDocument.location.reload(true);
});
}
});
</script>