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">
                &lt;!--
                    setTimeout("location.href = '';", 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?

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?

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 badges
Add a comment  | 

6 Answers 6

Reset to default 88

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