admin管理员组文章数量:1136388
I have a website which slides to a "section" called blog in my HTML. I want the user to simply see the page for a brief second or 2 then redirect to my blog engine.
Please suggest a time delayed redirect?
If i can redirect with a time delayed based on the click of the blog li:
<li data-target="blog" data-target-activation="click" class="tile icon_add_favourite">
<div>
<h2>Blog</h2><h3>13</h3>
<script type="text/JavaScript">
<!--
setTimeout("location.href = '';", 1500);
-->
</script>
</div>
</li>
UPDATE: This is sooo strange when the HTML5 slides to the section block the page is still rendering with all the code and therefore the JS should be fired by the click event then run the redirect based on the timer.
The solutions work in JS as the alert boxes pop up. Wonder why they dont work in my page?
I have a website which slides to a "section" called blog in my HTML. I want the user to simply see the page for a brief second or 2 then redirect to my blog engine.
Please suggest a time delayed redirect?
If i can redirect with a time delayed based on the click of the blog li:
<li data-target="blog" data-target-activation="click" class="tile icon_add_favourite">
<div>
<h2>Blog</h2><h3>13</h3>
<script type="text/JavaScript">
<!--
setTimeout("location.href = 'http://www.mysite.co.uk/blog';", 1500);
-->
</script>
</div>
</li>
UPDATE: This is sooo strange when the HTML5 slides to the section block the page is still rendering with all the code and therefore the JS should be fired by the click event then run the redirect based on the timer.
The solutions work in JS as the alert boxes pop up. Wonder why they dont work in my page?
Share Improve this question edited Mar 31, 2012 at 10:50 SOLDIER-OF-FORTUNE asked Mar 26, 2012 at 18:01 SOLDIER-OF-FORTUNESOLDIER-OF-FORTUNE 1,6445 gold badges39 silver badges68 bronze badges6 Answers
Reset to default 88Edit:
The problem i face is that HTML5 is all on one index page. So i need the timer to start on click of the blog link.
Try calling the setTimeout inside a click handler on the blog link,
$('#blogLink').click (function (e) {
e.preventDefault(); //will stop the link href to call the blog page
setTimeout(function () {
window.location.href = "blog.html"; //will redirect to your blog page (an ex: blog.html)
}, 2000); //will call the function after 2 secs.
});
Try using setTimeout
function like below,
setTimeout(function () {
window.location.href = "blog.html"; //will redirect to your blog page (an ex: blog.html)
}, 2000); //will call the function after 2 secs.
<meta http-equiv="refresh" content="2; url=http://example.com/" />
Here 2
is delay in seconds.
<script type="text/JavaScript">
setTimeout("location.href = 'http://www.your_site.com';",1500);
</script>
You can easily create timed redirections with JavaScript. But I suggest you to use location.replace('url') instead of location.href. It prevents to browser to push the site into the history. I found this JavaScript redirect tool. I think you could use this.
Example code (with 5 secs delay):
<!-- Pleace this snippet right after opening the head tag to make it work properly -->
<!-- This code is licensed under GNU GPL v3 -->
<!-- You are allowed to freely copy, distribute and use this code, but removing author credit is strictly prohibited -->
<!-- Generated by http://insider.zone/tools/client-side-url-redirect-generator/ -->
<!-- REDIRECTING STARTS -->
<link rel="canonical" href="https://yourdomain.com/"/>
<noscript>
<meta http-equiv="refresh" content="5;URL=https://yourdomain.com/">
</noscript>
<!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
<script type="text/javascript">
var url = "https://yourdomain.com/";
var delay = "5000";
window.onload = function ()
{
setTimeout(GoToURL, delay);
}
function GoToURL()
{
if(typeof IE_fix != "undefined") // IE8 and lower fix to pass the http referer
{
var referLink = document.createElement("a");
referLink.href = url;
document.body.appendChild(referLink);
referLink.click();
}
else { window.location.replace(url); } // All other browsers
}
</script>
<!-- Credit goes to http://insider.zone/ -->
<!-- REDIRECTING ENDS -->
Include this code somewhere when you slide to your 'section' called blog.
$("#myLink").click(function() {
setTimeout(function() {
window.navigate("the url of the page you want to navigate back to");
}, 2000);
});
Where myLink
is the id of your href.
You can include this directly in your buttun. It works very well. I hope it'll be useful for you.
onclick="setTimeout('location.href = ../../dashboard.xhtml
;', 7000);"
本文标签: javascripttime delayed redirectStack Overflow
版权声明:本文标题:javascript - time delayed redirect? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736952795a1957493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论