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.
<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 -->
Edit:
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.
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);"
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.
<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>