I need to redirect to specific url after 5 seconds after putting an error message. First i have used Javascript as below.
document.ready(window.setTimeout(location.href = "https://www.google.co.in",5000));
But it is not waiting for 5 seconds. Than I searched the issue in google than come to know that "document.ready()" is invoked when document is loaded at DOM, not at web browser.
Than i have used window.load() function of jQuery but still i am not getting what i want.
$(window).load(function() { window.setTimeout(window.location.href = "https://www.google.co.in",5000); });
Can anyone please let me know how exactly i need to do to wait for 5 seconds.
To redirect a webpage after 5 seconds, use the setInterval() method to set the time interval. Add the webpage in window. location. href object.
If you want to redirect a page automatically after a delay then you can use the setTimeout() method in JavaScript and it will call the above property after a time delay. The solution is very simple. The setTimeout() method will call a function or execute a piece of code after a time delay (in millisecond).
It happens due to page redirection. 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.
See the 'callbacks' section of the documentation: github.com/CodeSeven/toastr. Secondly, making an AJAX request then showing a notification is redundant if you're going to redirect anyway. Instead of making a single request you've made two and held up your user while they waited for the notification to go away.
It looks you are almost there. Try:
if(error == true){ // Your application has indicated there's an error window.setTimeout(function(){ // Move to a new location or you can do something else window.location.href = "https://www.google.co.in"; }, 5000); }
You actually need to pass a function inside the window.setTimeout()
which you want to execute after 5000 milliseconds, like this:
$(document).ready(function () { // Handler for .ready() called. window.setTimeout(function () { location.href = "https://www.google.co.in"; }, 5000); });
For More info: .setTimeout()
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