HTML页面跳转的5种方式 | 您所在的位置:网站首页 › 网页跳转方式 › HTML页面跳转的5种方式 |
下面列了五个例子来详细说明,这几个例子的主要功能是:在5秒后,自动跳转到同目录下的hello.html(根据自己需要自行修改)文件。 1) html的实现
优点:简单缺点:Struts Tiles中无法使用
2-1) javascript的实现[location.href] // 以下方式直接跳转 window.location.href='hello.html'; // 以下方式定时跳转 setTimeout("javascript:location.href='hello.html'", 5000);
setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。 优点:灵活,可以结合更多的其他功能缺点:受到不同浏览器的影响 2-2) 结合了倒数的javascript实现(IE) 5 var second = totalSecond.innerText; setInterval("redirect()", 1000); function redirect(){ totalSecond.innerText=--second; if(second -1){ document.getElementById('totalSecond').innerText = "my text innerText"; } else{ document.getElementById('totalSecond').textContent = "my text textContent"; }
2-5) 兼容IE和FF的带有倒数的跳转 5 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 -1) { document.getElementById('totalSecond').innerText = second--; } else { document.getElementById('totalSecond').textContent = second--; } } }
本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/p/4857864.html,如需转载请自行联系原作者 |
CopyRight 2018-2019 实验室设备网 版权所有 |