How to use the location.reload() In JQuery
The location.reload() method reloads the current web page emulating the clicking of the refresh button on the browser. The optional true parameter passed to the method is used to force the page to load from the server and ignore the browser cache.
Syntax:
location.reload(true)
Example:
html
<!DOCTYPE html> < html > < head > < title > How to refresh a page using jQuery? </ title > < script src = "https://code.jquery.com/jquery-3.3.1.min.js" > </ script > < script type = "text/javascript" > $(document).ready(function () { $("button").click(function () { location.reload(true); alert('Reloading Page'); }); }); </ script > </ head > < body > < center > < h1 style = "color: green" > w3wiki </ h1 > < b > How to refresh a page using jQuery? </ b > < p > w3wiki is a computer science portal with a huge variety of well,< br > written and explained computer science and programming articles, quizzes and interview questions. </ p > < button type = "button" > Button to Reload page </ button > </ center > </ body > </ html > |
Output:
How to refresh a page using jQuery?
In jQuery, you can use simple methods to refresh a page, ensuring that the current content is reloaded for a fresh experience. we have some common methods to refresh our page.
Here are several Approaches
Table of Content
- Using the location.reload()
- Using history.go(0):
- Using location.replace with the current page: