JSP实现页面自动跳转

时间:2022-01-28 08:46:34

 

一些页面自动跳转的实现

 

 

功能:

8

秒后,自动跳转到同目录下的

return.html

文件

 

 

 

1

html

的实现

 

<head>

<meta http-equiv="refresh" content="5;url=return.html">

</head>

 

2

javascript

的实现

 

<script language="javascript" type="text/javascript">

 

 

 

setTimeout("javascript:location.href='return.html'", 8000);

 

</script>

 

3

)结合了倒数的

javascript

实现(

IE

 

<span id="totalSecond">8</span>

 

<script language="javascript" type="text/javascript">

var second = totalSecond.innerText;

setInterval("redirect()", 1000);

function redirect(){

 

totalSecond.innerText=--second;

 

if(second<0) location.href='return.html';

}

</script>

 

3'

)结合了倒数的

javascript

实现(

firefox

 

<script language="javascript" type="text/javascript">

 

 

 

 

var second = document.getElementById('totalSecond').textContent;

 

 

 

 

setInterval("redirect()", 1000);

 

 

 

 

function redirect()

 

 

 

 

{

 

 

 

 

 

 

 

 

document.getElementById('totalSecond').textContent = --second;

 

 

 

 

 

 

 

 

if (second < 0) location.href = 'return.html';

 

 

 

 

}

</script>

 

4

)解决

Firefox

不支持

innerText

的问题

 

<span id="totalSecond">8</span>

 

<script language="javascript" type="text/javascript">

if(navigator.appName.indexOf("Explorer") > -1){

 

 

 

 

document.getElementById('totalSecond').innerText = "my text innerText";

} else{

 

 

 

 

 

 

 

 

document.getElementById('totalSecond').textContent = "my text textContent";

}

</script>

 

5

)整合

3

)和

3'

 

<span id="totalSecond">8</span>

 

<script language="javascript" type="text/javascript">

 

 

 

 

var second = document.getElementById('totalSecond').textContent;

 

 

 

 

 

if (navigator.appName.indexOf("Explorer") > -1)

 

 

 

 

{

 

 

 

 

 

 

 

 

second = document.getElementById('totalSecond').innerText;

 

 

 

 

} else

 

 

 

 

{

 

 

 

 

 

 

 

 

second = document.getElementById('totalSecond').textContent;

 

 

 

 

}

 

 

 

 

 

 

setInterval("redirect()", 1000);

 

 

 

 

function redirect()

 

 

 

 

{

 

 

 

 

 

 

 

 

if (second < 0)

 

 

 

 

 

 

 

 

{

 

 

 

 

 

 

 

 

 

 

 

 

location.href = 'return.html';

 

 

 

 

 

 

 

 

} else

 

 

 

 

 

 

 

 

{

 

 

 

 

 

 

 

 

 

 

 

 

if (navigator.appName.indexOf("Explorer") > -1)

 

 

 

 

 

 

 

 

 

 

 

 

{

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

document.getElementById('totalSecond').innerText = second--;

 

 

 

 

 

 

 

 

 

 

 

 

} else

 

 

 

 

 

 

 

 

 

 

 

 

{

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

document.getElementById('totalSecond').textContent = second--;

 

 

 

 

 

 

 

 

 

 

 

 

}

 

 

 

 

 

 

 

 

}

 

 

 

 

}

</script>

 

不在

jsp

页面中嵌套

java

代码片段

 

<html>

<head>

<script type="text/javascript">

 

 

 

 

function delayedRedirect(){

window.location = http://localhost:8080/redirect/login.jsp;

}

</script>

</head>

<body onLoad="setTimeout('delayedRedirect()',3000)">

<h2>3

秒钟后将自动跳转到登陆页面

 </h2>

</body>

</html>