Avatar of Robert Granlund
Robert Granlund
Flag for United States of America asked on

jQuery reload entire page after Confirm alert is clicked

jQuery.  Is there a way to reload an entire page, after a confirmation alert is clicked?

Avatar of undefined
Last Comment
Dénes Kellner

8/22/2022 - Mon
David S.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Dénes Kellner

One of the solutions is location.reload(), as David mentioned. This will refresh your page and stay at the scrolled position. If this is what you want, go with it.

If you want to refresh the page and go to the top, use "location.href = location.href" instead; this will reload and go to the top which is sometimes useful when the page content changes a lot due to user action. Side effect: this will use a GET request even when the original page has been shown by a POST. Also useful to avoid the confirmation nagging in some postback situations.

Also, you can give location.reload() an argument (true/1/something) to make sure it fetches every resource - this is the equivalent of Ctrl-F5. Use this when the user action involves "heavy" items that are usually cached, typically images.

Finally, you can make "indoor reloads" with jQuery which allows you to only replace a dom element with the fetched fresh contents. See $.load() on this.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.