实现HTML页面跳转的几种方法

转自:微点阅读  https://www.weidianyuedu.com

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

1) html的实现

1

2

3

4

5

6

<head>

<!-- 以下方式只是刷新不跳转到其他页面 -->

<meta http-equiv="refresh" content="10">

<!-- 以下方式定时转到其他页面 -->

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

</head>

优点:简单

缺点:Struts Tiles中无法使用

2) javascript的实现

1

2

3

4

5

6

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

// 以下方式直接跳转

window.location.href="hello.html";

// 以下方式定时跳转

setTimeout("javascript:location.href="hello.html"", 5000);

</script>

优点:灵活,可以结合更多的其他功能

缺点:受到不同浏览器的影响

3) 结合了倒数的javascript实现(IE)

1

2

3

4

5

6

7

8

9

<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)

1

2

3

4

5

6

7

8

9

<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的问题

1

2

3

4

5

6

7

8

<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")

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

<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>

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
function doublechooseclick() { //alert("doublechooseclick"); $.ajax({ type: "POST", dataType: "json", url: "/HttpUrl/UserReg.ashx?UserMail=" + emailTxt, success: function (msg) { // alert(msg.user); var user = msg.user; var balance = msg.balance; // alert(user); /// alert(balance); if (user != "") { location.href = "RegSuccess.html?user=" + user + "&balance=" + balance; //location.href实现客户端页面的跳转 // location.href = "RegSuccess.html"; //location.href实现客户端页面的跳转 } else { alert("注册失败!"); return; } } }); } //function doublechooseclick() { // $.post("/HttpUrl/UserReg.ashx", { id: "1", name: "join" }, function () { location.href = "/User/RegSuccess.html"; }); //} /**********************************************************************************/ //var falg = true; //定义是否通过的标志 //function bt_reg_C() { // location.href = "/User/reg.html "; //} //$(document).ready(function () { // $("#VerifyCode").bind("click", function () { // $("#VerifyCode img").attr("src", "/Httpurl/RandomImage.ashx?time=" + Math.random()); // }); // $("#bt_login").bind("click", function () { // //alert("1"); // login(); // }); //}); //function login() {///登陆 // var falg = ""; // var username = $("#UserName").val(); // var password = $("#PassWord").val(); // var val = $("#Validate").val(); // $.ajax({ // type: "POST", // url: "/HttpUrl/UserReg.ashx?Validate=" + val, // success: function (msg) { // var msg = "ok"; ///测试先写死,到时候进行屏蔽 // if (msg == "ok") { // falg = true; // if (falg) { // $.ajax({ // type: "POST", // url: "/HttpUrl/index.ashx?type=3&uname=" + username + "&pwd=" + password, // success: function (msg) { // if (msg.user == username) { // downdan("ssq", username); ///下单 // } // else { // alert("用户名密码错误!"); // } // } // }); // } // } // else { // alert("验证码不一致!"); // falg = false; // } // } // }); //} ///跳转按钮中的事件 最强护卫 function sure() { var combination = getcombination(); var amount = $("#pt_bs").val() - 0; var posturl = "/order/sure"; var count; var btype = $("input[name='buyType']:checked").val(); var title; //追号名称: if (btype == 3) { posturl = "/order/autoplay"; count = $("#lx").val(); title = $(".chasing_name :text").val(); if (title == null || title == '') { title = '\u8ffd\u53f7'; } if (count == null || count <= 0) { alert("\u8bf7\u8f93\u5165\u8ffd\u53f7\u7684\u671f\u6570"); return; } } var lotterytype = $("#lotterytype").val(); if ($("#lx_buy").attr("checked") == "checked") { posturl = "/order/autoplay"; } $.ajax({ //一个Ajax过程 type: "post", url: posturl, dataType: 'json', data: { combination: combination, amount: amount, lotterytype: lotterytype, count: count, title: title }, success: function (data) { if (data.success == true) { tdialog("\u6210\u529f ", "\u8d2d\u4e70\u6210\u529f,\u8bf7\u4ed8\u6b3e"); } else if (data.status == 0) { $.ajax({ type: "get", url: "/home/login", data: { isdialog: true }, success: function (data) { if (btype == 1) { var m = "\u76f4\u63a5\u8d2d\u4e70-\u65e0\u9700\u767b\u5f55\u5c31\u53ef\u8d2d\u4e70\u771f\u5b9e\u59d3\u540d"; m += "\u8eab\u4efd\u8bc1\u53f7\u7801"; m += "\u4e2d\u5956\u8054\u7cfb\u624b\u673a"; m += ""; tdialog("\u8bf7\u767b\u5f55", m + data); } else if (btype == 3) { tdialog("\u8bf7\u767b\u5f55", data); } } }); } else if (data.status == 2) { tdialog("\u8bf7\u5b8c\u5584\u8eab\u4efd\u4fe1\u606f", "\u70b9\u6b64\u5b8c\u5584\u4fe1\u606f"); } else { tdialog("\u5931\u8d25\u4e86", data.info); } } }); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值