[英]html pages auto cicling using js script
我有一个可打印html页面的servlet。 我希望这些页面使用js脚本自动循环。 因此,我加载了一个html页面,三秒钟后刷新,然后加载了另一个html页面(由相同的servlet打印)。
在servlet中:-阅读会话,在该会话中我存储要打印的页面的索引; -基于此索引,我打印页面并更新索引(如果我要打印最后一页,则索引会增加或返回0)-将索引存储在div元素中,以便可以通过javascript函数查找并刷新带有js函数的html页面
out.println("<div id=\"storedDiv\">");
int indexRefresh= (int) request.getSession().getAttribute("indexRefresh");
out.println(Integer.toString(indexRefresh) );
indexRefresh=indexRefresh+1;
if (indexRefresh==Tot) {
indexRefresh=0;
}
request.getSession().setAttribute("indexRefresh", indexRefresh);
out.println("</div>");
js函数在html页面中找到div元素并更新页面
function refresh(){
var element = document.getElementById("storeDiv");
if (element==0){
setTimeout(function() {
window.location.href = "http://localhost:9080/HydroGui/Query?anno=2018&id=1";
}, 3000);
}
if (element==1){
setTimeout(function() {
window.location.href = "http://localhost:9080/HydroGui/Query?anno=2018&id=2";
}, 3000);
}
}
但是我在哪里调用该函数? 如果我使用
window.onload = refresh();
在将索引存储在div中之前进行页面加载。 那么什么是最好的方法呢?
使用innerHTML
var element = document.getElementById("storeDiv").innerHTML;
if (element == '0') {
//...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.