HTML页面跳转的5种方法 | 您所在的位置:网站首页 › html中跳转其他网页的命令代码 › HTML页面跳转的5种方法 |
下面列了五个例子来详细说明,这几个例子的主要功能是:在5秒后,自动跳转到同目录下的hello.html(根据自己需要自行修改)文件。1) html的实现
优点:简单缺点:Struts Tiles中无法使用
2) javascript的实现 // 以下方式直接跳转 window.location.href='hello.html'; // 以下方式定时跳转 setTimeout("javascript:location.href='hello.html'", 5000); 优点:灵活,可以结合更多的其他功能缺点:受到不同浏览器的影响3) 结合了倒数的javascript实现(IE) 5 var second = totalSecond.innerText; setInterval("redirect()", 1000); function redirect(){ totalSecond.innerText=--second; if(second -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--; } } }
|
CopyRight 2018-2019 实验室设备网 版权所有 |