<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb" />
</head>
<body>
<!--先编写好网页布局-->
<h3>操作成功</h3>
<label id="second">5</label>
<span>秒后回到主页</span>
<a href="http://www.imooc.com" target="_self">返回</a>
<script type="text/javascript">
var time = 5;
function clock() {
//获取显示秒数的元素,通过定时器来更改秒数。
document.getElementById("second").innerHTML = time;
time = time - 1;
if(time==-1){
clearInterval(i);
window.location.href="http://www.imooc.com";
}
}
i=setInterval(clock, 1000);
//通过window的location和history对象来控制网页的跳转。
</script>
</body>
</html>
<!DOCTYPE html><html> <head> <title>浏览器对象</title> <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> <style type="text/css"> #timeStep { font-weight:bold; } .backStyle { color:blue; text-decoration:underline; } </style> </head> <body> <!--先编写好网页布局--> <h2>操作成功</h2> <p><span id="timeStep">5</span>秒后回到主页 <span class="backStyle" onclick="goback()">返回</span></p> <script type="text/javascript"> var stepDom = document.getElementById("timeStep"); var step = parseInt(stepDom.innerText); var stepInterval = setInterval(onload, 1000); function onload() { step = step-1; stepDom.innerText = step; if (step == 1) { clearInterval(stepInterval); window.open("https://www.imooc.com", "_blank"); } } function goback() { window.history.back(); } </script> </body></html>