HTML页面跳转的5种方法
下面列了五个例子来详细说明,这几个例子的主要功能是:在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> |
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> |
[SheetJS] js-xlsx模块学习指南
漂亮又好用的Redis可视化客户端汇总
Visual Studio 2015 出现 NuGet 安装程序包错误解决方法
vs2015使用nuget包管理器安装失败
C# 尝试还原程序包是出错:找不到“XXXXX”版本的程序包“XXXXXX”
基于flink和drools的实时日志处理
Docker常用命令
Laravel5打印所有运行SQL
Laravel5版本在sql查询时用when方便条件判断查询【闭包方式】
- 最新文章
-
SQLServer查看各个表大小
阿里云cdn更新证书提示重复
IOS端企业微信list页面无法href需要双击问题
企业微信weui picker简单例子
一个模拟select
企业微信通讯录-发送消息id转换
企业微信政务微信文档地址
企业微信通讯录替换Picker问题
7种 JS 创建对象的经典方式
Oracle中的NVL,NVL2,NULLIF,COALESCE函数
- 热门文章
-
常用函数DECODE()、LAG()、LEAD() 基础用法
FineReport单元格标识说明
根据提供的数据求出该日期所在的季度
finereport报表饼图联动
finereport报表禁用右键
JS实现点击参数面板按钮显示或隐藏数据
JavaScript 数组——filter()、map()、some()、every()、forEach()、lastIndexOf()、indexOf()
Spring Boot:The field file exceeds its maximum permitted size of 1048576 bytes
springboot解决跨域问题(Cors)
Springboot2.x实现文件上传下载