等待两秒钟,然后在jquery中自动重定向另一个页面
waiting two seconds then auto redirect another page in jquery?
HTML结构:
<div class="user_register border_y">
<div>
<span style="color:green;"> after two seconds then auto redirect </span><br><br>
<a href="http://example.com/down/test.html">if you don't want to wait you can click this。</a></div></div>
我想使用jquery获得:两秒钟后,然后自动重定向到a
标签页面。我该怎么办?
你甚至不需要jQuery;香草JS将工作得很好…
<a id="link" href="http://example.com">Go NOW!!!</a>
JS:
window.setTimeout(function() {
location.href = document.getElementsByClassName("user_register border_y")[0].getElementsByTagName("a")[0].href;
}, 2000);
getElementsByClassName
不能在所有浏览器中工作;所以要确保你提供了一个备用的
使用setTimeout
:
setTimeout(function() {
window.location.href = $("a")[0].href;
}, 2000);
为什么使用JavaScript?
<head>
<meta http-equiv="refresh" content="2;url=http://example.com/down/test.html">
</head>
<body>
<div class="user_register border_y">
<div>
<span style="color:green;"> after two seconds then auto redirect </span><br><br>
<a href="http://example.com/down/test.html">if you don't want to wait you can click this。</a></div></div>
下面是一个基于你的描述的简单脚本:
function redirect(){
window.location = $('a').attr('href');
}
setTimeout(redirect, 2000);
演示:http://jsfiddle.net/KesU9/
在主体OnLoad
使用下面的简单代码<body onLoad="setTimeout(location.href='http://www.newpage.com', '2000')">
使用JavaScript重定向。例如:
<script type="text/javascript">
var time = 15; // Time coutdown
var page = "http://www.redirect-url.com/";
function countDown(){
time--;
gett("timecount").innerHTML = time;
if(time == -1){
window.location = page;
}
}
function gett(id){
if(document.getElementById) return document.getElementById(id);
if(document.all) return document.all.id;
if(document.layers) return document.layers.id;
if(window.opera) return window.opera.id;
}
function init(){
if(gett('timecount')){
setInterval(countDown, 1000);
gett("timecount").innerHTML = time;
}
else{
setTimeout(init, 50);
}
}
document.onload = init();
</SCRIPT>
在body tab
之后添加以下代码<h3>Auto redirect after <span id="timecount"></span> second(s)!</h3>
相关文章:
- 如何在一页网站中使用PHP重定向到一个页面
- php重定向到一个空白页面
- 在发布表单输入时,我可以重定向到一个新的php文件吗
- Firefox弹出窗口“;这个网页被重定向到一个新的位置“;在每个requestPromise ajax调用上,有什么方
- Facebook重定向到一个空白的权限请求页面
- 如何在组合框值更改时自动重定向下一个 jsp 页面
- 如何在更改字段中的选择后重置另一个字段中的数据
- 如果另一个下拉列表选择发生更改,则重置另一个下拉列表
- 重置另一个字段Primefaces的字段值
- javascript可以将我的页面重定向到一个url,如果失败,则不会发出警报
- 点击产品,它会自动重定向另一个网站
- 在选择电台,重定向到一个链接
- Phonegap Hybrid App - JavaScript重定向使一个绝对定位的元素闪烁并显示后面的内容
- 我需要做一个网站重定向到一个页面后21.45至10.00
- 如何使javascript加载新数据每次(不使用缓存数据),当我重定向到一个处理程序(页)在鼠标点击
- 重定向选择一个选择输入
- 我如何得到chrome.tab .update重定向到一个url
- 检查在旧版Internet Explorer中事件重定向期间一个事件是否与另一个事件相同
- 等待两秒钟,然后在jquery中自动重定向另一个页面
- Php重定向到一个服务器到另一个服务器的Php页面