[英]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.