
上QQ阅读APP看书,第一时间看更新
2.3.5 设置网页的定时跳转
使用 <meta>标签可以使网页在经过一定时间后自动刷新,这可以通过将 http-equiv 属性值设置为refresh 来实现。content 属性值可以设置为更新时间。
在浏览网页时经常会看到一些欢迎信息的页面,在经过一段时间后,这些页面会自动转到其他页面,这就是网页的跳转。
语法:
<meta http-equiv="refresh" content="跳转的时间;url=跳转到的地址">
说明:
在该语法中,refresh 表示网页的刷新,在 content 中设置刷新的时间和刷新后的链接地址,时间和链接地址之间用分号相隔。默认情况下,跳转时间以秒(s)为单位。
【例2-1】
在进入网页后首先显示欢迎界面,5s后自动跳转到网页的内容区,如图2-2和图2-3所示。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="5;url=target/index.html">
<title>网页的定时跳转</title>
</head>
<body>
<h1>欢迎来到这个页面,5s后将自动跳转到其他页面</h1>
</body>
</html>

图2-2 欢迎界面

图2-3 跳转后的页面