页面定时跳转(读秒)
生活随笔
收集整理的這篇文章主要介紹了
页面定时跳转(读秒)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
頁面定時(shí)刷新(頁面讀秒操作)* 響應(yīng)的頭 refresh <meta http-equiv="refresh" content="5;url=/day10/response/login.html">
發(fā)送http頭,控制瀏覽器定時(shí)刷新網(wǎng)頁(refresh)
多學(xué)一招:HTML<meta>標(biāo)簽來控制瀏覽器行為
package cn.learn.response;import java.io.IOException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/*** 頁面的定時(shí)跳轉(zhuǎn)* @author Administrator**/
public class RefreshServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {// 讀秒操作response.setContentType("text/html;charset=UTF-8");response.getWriter().write("<h1>頁面將在5秒后跳轉(zhuǎn)</h1>");// 通過refresh頭完成頁面刷新response.setHeader("refresh", "5;url=/day10/response/login.html");}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request, response);}}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 5秒后跳轉(zhuǎn) -->
<meta http-equiv="refresh" content="5;url=/day10/response/login.html">
<title>頁面定時(shí)跳轉(zhuǎn)(讀秒)</title>
</head>
<body onload="run()"><h2>頁面將在<span id="spanId">5</span>秒后跳轉(zhuǎn)</h2></body><script type="text/javascript">/* 讀秒的操作頁面一加載,加載事件 onload執(zhí)行讀秒的操作,每隔一秒變一次。每隔一秒,js的定時(shí)器*/var x = 5;function run(){var span = document.getElementById("spanId");span.innerHTML = x;x--;window.setTimeout("run()", 1000);}</script></html>
?
總結(jié)
以上是生活随笔為你收集整理的页面定时跳转(读秒)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。