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?
To redirect a webpage after 5 seconds, use the setInterval() method to set the time interval. Add the webpage in window. location. href object.
To redirect from an HTML page, use the META Tag. With this, use the http-equiv attribute to provide an HTTP header for the value of the content attribute. The value of the content is the number of seconds; you want the page to redirect after.
To delay a link with inline javascript, just set your href attribute as href="javascript:setTimeout(()=>{window. location = 'URL' },500);" . When you replace the URL with your link, just make sure it is inside the ' ' .
Conclusion. setTimeout() is a method that will execute a piece of code after the timer has finished running. let timeoutID = setTimeout(function, delay in milliseconds, argument1, argument2,...); The delay is set in milliseconds and 1,000 milliseconds equals 1 second.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With