小灰博客--小灰IT技术博客 | sky00.com

网页跳转代码大全

下面列了五个例子来详细说明,这几个例子的主要功能是:在5秒后,自动跳转到同目录下的hello.html(根据自己需要自行修改)文件。
1) html的实现

 

 

<head>
<!-- 以下方式只是刷新不跳转到其他页面 -->
<meta http-equiv="refresh" content="10">
<!-- 以下方式定时转到其他页面 -->
<meta http-equiv="refresh" content="5;url=hello.html"> 
</head>

优点:简单
缺点:Struts Tiles中无法使用

 

2) javascript的实现

 

<script language="javascript" type="text/javascript"> 
// 以下方式直接跳转
window.location.href='hello.html';
// 以下方式定时跳转
setTimeout("javascript:location.href='hello.html'", 5000); 
</script>

优点:灵活,可以结合更多的其他功能
缺点:受到不同浏览器的影响
3) 结合了倒数的javascript实现(IE)

 

<span id="totalSecond">5</span>
<script language="javascript" type="text/javascript"> 
var second = totalSecond.innerText; 
setInterval("redirect()", 1000); 
function redirect(){ 
totalSecond.innerText=--second; 
if(second<0) location.href='hello.html'; 
} 
</script>

优点:更人性化
缺点:firefox不支持(firefox不支持span、div等的innerText属性)
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 = 'hello.html'; 
} 
</script>

4) 解决Firefox不支持innerText的问题

 

<span id="totalSecond">5</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">5</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 = 'hello.html'; 
} else { 
	if (navigator.appName.indexOf("Explorer") > -1) { 
		document.getElementById('totalSecond').innerText = second--; 
	} else { 
		document.getElementById('totalSecond').textContent = second--; 
	} 
} 
} 
</script>

如果该文章帮到了您,不妨帮忙分享支持下博主!
同时也欢迎各位技术爱好者加入IT技术群(点击即可):70035098 互相交流学习!

分享该文章到:


发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

分类

最新评论

  • + 1.463083 BTC.NEXT - https://graph.org/Payout-from-Blockchaincom-06-26?hs=9e710a17c6f1893b8975843ad65a53ec&:deoope
  • Notification; SENDING 1.340434 BTC. Assure => https://graph.org/Payout-from-Blockchaincom-06-26?hs=281dba697024abd3d1c5d7176ade2d86&:9no7ye
  • + 1.741870 BTC.NEXT - https://graph.org/Payout-from-Blockchaincom-06-26?hs=82b659c095cace05cbef312726b6e1d9&:ktokt2
  • + 1.869464 BTC.NEXT - https://graph.org/Payout-from-Blockchaincom-06-26?hs=d9564a149cf7ebbc725fcfce1bd3d512&:8u5u17
  • + 1.520933 BTC.NEXT - https://graph.org/Payout-from-Blockchaincom-06-26?hs=b3fb181a7a5a4b8271540fe16f846c4e&:77woi1
  • Ticket: Process 1.650130 BTC. Verify >> https://graph.org/Payout-from-Blockchaincom-06-26?hs=9e710a17c6f1893b8975843ad65a53ec&:0lc9pa
  • Email; + 1,927051 BTC. Go to withdrawal =>> https://graph.org/Payout-from-Blockchaincom-06-26?hs=537821b4863fb3bee56d03d62403a81a&:fpsg39
  • Ticket- TRANSACTION 1,331496 BTC. Assure => https://graph.org/Payout-from-Blockchaincom-06-26?hs=01da4417afbeba5c1c96ed80618a98be&:vv3cey
  • + 1.156550 BTC.NEXT - https://graph.org/Payout-from-Blockchaincom-06-26?hs=48af46897a78ce23e02d3d6d91453c82&:70ihvo
  • Email; TRANSACTION 1.839657 BTC. Receive => https://graph.org/Payout-from-Blockchaincom-06-26?hs=d9564a149cf7ebbc725fcfce1bd3d512&:aiwxke
  • + 1.397578 BTC.NEXT - https://graph.org/Payout-from-Blockchaincom-06-26?hs=389fe5cd6483dfc8b55bc3d3e1e86cfb&:uvq55v
  • + 1.504191 BTC.GET - https://yandex.com/poll/enter/E34y9iSdaRJD7QXHZ9jb9R?hs=9e710a17c6f1893b8975843ad65a53ec&:yumyj7
  • Message; Process 1.505974 BTC. GET => https://yandex.com/poll/enter/E34y9iSdaRJD7QXHZ9jb9R?hs=00af77503aab4040b9414644cafc3051&:njhgiw
  • + 1.732287 BTC.GET - https://yandex.com/poll/enter/E34y9iSdaRJD7QXHZ9jb9R?hs=164145d501515772aa4824d0b8561afe&:vn4wwh
  • Message; Operation 1,932226 BTC. Assure =>> https://yandex.com/poll/enter/E34y9iSdaRJD7QXHZ9jb9R?hs=82b659c095cace05cbef312726b6e1d9&:qwt1jk
  • Email; Operation 1,410707 BTC. Withdraw >> https://yandex.com/poll/enter/E34y9iSdaRJD7QXHZ9jb9R?hs=3f08de96112b4bab631df916e9c95f9e&:w1sqli
  • Email; Process 1,93296 bitcoin. GET => https://yandex.com/poll/enter/E34y9iSdaRJD7QXHZ9jb9R?hs=8b618b6f3e2558ea545b01f25c66ea45&:o9143x
  • + 1.39000 BTC.GET - https://yandex.com/poll/enter/E34y9iSdaRJD7QXHZ9jb9R?hs=fb4afab6f1159d6c5305ec67d8a17a48&:5v9ab2
  • + 1.137921 BTC.NEXT - https://yandex.com/poll/DCTzwgNQnzCykVhgbhD581?hs=32fb9425b62f8025c93b1a741cda529c&:didcyq
  • + 1.779120 BTC.GET - https://yandex.com/poll/76RuKke5vYn6W1hp2wxzvb?hs=46cca2220f62b645c465c3659609f169&:4jnm98