是否有使用jQuery一个给一段时间后重定向到一个特定的URL的方式?JQuery的重定向到URL后指定时间
46
A
回答
91
您可以使用setTimeout()
功能:
// Your delay in milliseconds
var delay = 1000;
setTimeout(function(){ window.location = URL; }, delay);
+2
笑几乎相同但在24秒快速:P –
45
你并不真正需要的jQuery这一点。你可以使用setTimeout方法与普通的JavaScript做到这一点:
// redirect to google after 5 seconds
window.setTimeout(function() {
window.location.href = 'http://www.google.com';
}, 5000);
12
$(document).ready(function() {
window.setInterval(function() {
var timeLeft = $("#timeLeft").html();
if(eval(timeLeft) == 0){
window.location= ("http://www.technicalkeeda.com");
}else{
$("#timeLeft").html(eval(timeLeft)- eval(1));
}
}, 1000);
});
4
只需使用:
setTimeout("window.location.href='yoururl';",4000);
..where的 '4000' 是m.second
6
您可以使用
$(document).ready(function(){
setTimeout(function() {
window.location.href = "http://test.example.com/;"
}, 5000);
});
2
我做了一个si多个演示,提示X秒数并重定向以设置url。如果您不想等到计数结束,只需点击计数器即可立即重定向。 简单的计数器,可以在页面中间点时间倒计时。 您可以在点击或加载某个页面时运行它。
我为此也做了GitHub库: https://github.com/GlupiJas/redirect-counter-plugin
JS代码示例:
// FUNCTION CODE
function gjCountAndRedirect(secounds, url)
{
$('#gj-counter-num').text(secounds);
$('#gj-counter-box').show();
var interval = setInterval(function()
{
secounds = secounds - 1;
$('#gj-counter-num').text(secounds);
if(secounds == 0)
{
clearInterval(interval);
window.location = url;
$('#gj-counter-box').hide();
}
}, 1000);
$('#gj-counter-box').click(function() //comment it out -if you dont want to allo count skipping
{
clearInterval(interval);
window.location = url;
});
}
// USE EXAMPLE
$(document).ready(function() {
//var
var gjCountAndRedirectStatus = false; //prevent from seting multiple Interval
//call
$('h1').click(function(){
if(gjCountAndRedirectStatus == false)
{
gjCountAndRedirect(10, document.URL);
gjCountAndRedirectStatus = true;
}
});
});
1
是,该解决方案是使用setTimeout,像这样:
var delay = 10000;
var url = "https://stackoverflow.com";
var timeoutID = setTimeout(function() {
window.location.href = url;
}, delay);
注意,结果被存储到timeoutID
。如果出于某种原因,你需要取消订单,你只需要调用
clearTimeout(timeoutID);
相关问题
- 1. 在特定时间后重定向
- 2. 重定向到修改后的URL
- 3. 的.htaccess重定向到外部URL,同时隐藏重定向
- 4. Url在特定服务器时间或本地时间后重定向
- 5. ASP.NET MVC - RequireHttps - 指定重定向URL
- 6. jQuery在页面加载设定时间后重定向
- 7. Laravel 5 - 注册后重定向到URL
- 8. PrettyFaces登录后重定向到RESTful url
- 9. 如何在会话超时后重定向到指定页面
- 10. 如何通过Codeigniter中的重定向URL重定向到URL?
- 11. URL重写和301重定向...重定向到原始URL
- 12. .htaccess重定向到外部URL,同时隐藏重定向
- 13. PHP的重定向到URL
- 14. 如何Servlet的重定向到指定的URL
- 15. 的.htaccess重定向到特定的URL
- 16. 的.htaccess重定向到散列(URL片段)如果指定
- 17. Auth0不重定向到指定的URL(反应)
- 18. 登录后预期的URL重定向+默认重定向?
- 19. 重定向时隐藏URL
- 20. 日期和时间后重定向
- 21. HTTPS重定向到特定的URL
- 22. PHP 301重定向到定义的URL
- 23. url重定向从_到 - htaccess
- 24. Url Shortener重定向到index.html
- 25. 重定向到URL,如果
- 26. plupload不重定向到url
- 27. 重定向到URL从PDF
- 28. 添加#到URL重定向?
- 29. 春重定向到URL
- 30. URL重定向
你应该接受正确的答案... – Legionar
如果你想跨浏览器和搜索引擎优化支持:[重定向发生器(HTTP: //insider.zone/tools/client-side-url-redirect-generator/) –