Page Redirect after X seconds wait using JavaScript

0 votes

After displaying an error notice, I need to redirect to a specified URL after 5 seconds. 

First, I utilized Javascript as seen below.

document.ready(window.setTimeout(location.href = "https://www.google.co.in",5000));

However, it is not waiting 5 seconds. Then I googled the problem and discovered that "document.ready()" is called when a document is loaded at the DOM rather than the web browser.

Then I used jQuery's window.load() function, but I still don't get what I want.

$(window).load(function() {
               window.setTimeout(window.location.href = "https://www.google.co.in",5000);
            });

Could someone kindly tell me what I need to do to wait 5 seconds?

Sep 28, 2022 in Java by Nicholas
• 7,760 points
1,140 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Java

0 votes
1 answer

Refresh a page using JavaScript or HTML

This can be solved by using the ...READ MORE

answered Feb 18, 2022 in Java by Aditya
• 7,680 points
515 views
0 votes
1 answer

Refresh a page using JavaScript or HTML

window.location.reload(); in JavaScript <meta http-equiv="refresh" content="1"> in HTML ...READ MORE

answered Nov 7, 2022 in Java by Damonlang
• 700 points
640 views
0 votes
2 answers
0 votes
1 answer

Convert Milliseconds to “X mins, x seconds” in Java?

I wrote a function which converts milliseconds ...READ MORE

answered May 30, 2018 in Java by Rishabh
• 3,620 points
3,107 views
0 votes
2 answers

Scanner is skipping nextLine() after using next() or nextFoo()?

use input.nextLine(); after your nextInt() function for example:- input.nextInt(); ...READ MORE

answered May 11, 2019 in Java by Sourav Dangi
17,964 views
0 votes
1 answer

How to call a method after a delay in Android using Java?

final Handler handler = new Handler(); handler.postDelayed(new Runnable() ...READ MORE

answered Jun 11, 2018 in Java by Akrati
• 3,190 points
5,337 views
0 votes
1 answer

Using setTimeout to delay timing of jQuery actions

The JavaScript setTimeout () function  is used ...READ MORE

answered May 30, 2022 in Java by gaurav
• 23,260 points
7,982 views
0 votes
1 answer

Best cross-browser method to capture CTRL+S with JQuery?

$(window).keypress(function(event) { if ...READ MORE

answered May 30, 2022 in JQuery by gaurav
• 23,260 points
1,561 views
0 votes
1 answer

jQuery.inArray(), how to use it right?

The jQuery inArray() method is used to find ...READ MORE

answered Jun 1, 2022 in JQuery by Edureka
• 13,690 points
513 views
0 votes
1 answer

Which keycode for escape key with jQuery

27 is the code for the escape key. ...READ MORE

answered Jun 1, 2022 in JQuery by Edureka
• 13,690 points
3,218 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP