time delayed redirect?

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">
                &lt;!--
                    setTimeout("location.href = 'http://www.mysite.co.uk/blog';", 1500);
                --&gt;
                </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?


Solution 1:

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.

Solution 2:

<meta http-equiv="refresh" content="2; url=http://example.com/" />

Here 2 is delay in seconds.

Solution 3:

 <script type="text/JavaScript">
      setTimeout("location.href = 'http://www.your_site.com';",1500);
 </script>

Solution 4:

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 -->

Solution 5:

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.