Javascript函数没有在我的Flask应用程序上运行


<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="load" class="load">
<h3 >{{load}}</h3>
<img  src="{{ load }}" id="image" style="height:500px;width:500px;"  />
</div>
<script type="text/javascript">
document.getElementById("image").addEventListener("loadstart", refresh);
function refresh() {
window.location.reload();
}
</script>
</body>
</html>

Flask服务器正在上运行http://0.0.0.0:5000/,在每个HTTPPOST新图像被加载到src="之后;{{load}}";。我希望网站使用刷新功能自行刷新,但它不起作用。有人知道为什么吗?

当脚本运行时,图像已经加载

此外,图像没有loadStart

使用窗口加载代替

并给用户一个享受图像的机会

window.addEventListener("load", function() {
setTimeout(function() {
window.location.reload(1);
},3000)
})
<div id="load" class="load">
<h3>{{load}}</h3>
<img src="{{ load }}" id="image" style="height:500px;width:500px;" />
</div>

您也可以只加载图像

window.addEventListener("load", function() {
setTimeout(function() {
document.getElementById('image').src = '{{ load }}'; // you may want to add something random to not cache
},3000)
})
<div id="load" class="load">
<h3>{{load}}</h3>
<img src="{{ load }}" id="image" style="height:500px;width:500px;" />
</div>

最新更新