How to Refresh a Page using jQuery?
Last Updated :
08 Oct, 2024
Refreshing a page using jQuery allows you to programmatically reload the current webpage, ensuring updated content or resetting the page's state. It can be done using location.reload() method.
Refresh a Page using location.reload() Method
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: This example refreshing the web page on a button click. It display a message Reloading Page and then reloads the page.
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>
</head>
<body style="text-align: center;">
<h1 style="color: green">
GeeksforGeeks
</h1>
<b>
How to refresh a page
using jQuery?
</b>
<p>
GeeksforGeeks 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>
Button to Reload page
</button>
<script>
$(document).ready(function () {
$("button").click(function () {
location.reload(true);
alert('Reloading Page');
});
});
</script>
</body>
</html>
Output

Refresh a Page using history.go(0)
The history.go() method loads a URL from the browser's history depending on the parameter passed to it. If the parameter passed is '0', it reloads the current page.
Syntax
history.go(0);
Example: In this example, we are using jQuery to refresh the page when a button is clicked. It triggers history.go(0) to reload the page and displays a Reloading Page alert.
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>
</head>
<body style="text-align: center;">
<h1 style="color: green">
GeeksforGeeks
</h1>
<b>
How to refresh a page
using jQuery?
</b>
<p>
GeeksforGeeks is a computer science
portal with a huge variety of well
written <br> and explained computer
science and programming articles,
quizzes and interview questions.
</p>
<button>
Button to Reload page
</button>
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
history.go(0);
alert('Reloading Page');
});
});
</script>
</body>
</html>
Output

Refresh a Page using location.replace() with Current Page
The location.replace() method can be used by passing the location.pathname as a parameter. The location.pathname returns the current url and passing that on to location.replace() reloads the current page.
Syntax
location.replace(location.pathname);
Example: In this example, we are using jQuery to refresh the page when a button is clicked by calling location.replace(location.pathname) and displays an alert saying Reloading Page.
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>
</head>
<body style="text-align: center;">
<h1 style="color: green">
GeeksforGeeks
</h1>
<b>
How to refresh a page
using jQuery?
</b>
<p>
GeeksforGeeks is a computer science
portal with a huge variety of well
written and explained <br>
computer science and programming
articles, quizzes and interview
questions.
</p>
<button>
Button to Reload page
</button>
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
location.replace(location.pathname);
alert('Reloading Page');
});
});
</script>
</body>
</html>
Output:

jQuery is an open source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous with it's philosophy of “Write less, do more". You can learn jQuery from the ground up by following this jQuery Tutorial and jQuery Examples.
Similar Reads
How to make Refresh icon using jQuery Mobile ? jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be making Refresh icon using jQuery Mobile. Approach: First, add jQuery Mobile scripts needed for your project. <link rel="stylesheet" h
1 min read
How to refresh a page using selenium JavaScript ? Selenium is a tool with the help of it, we can perform automation testing in web browsers. According to the official documentation of Selenium - Selenium can automate anything present on the web. Automation scripts in Selenium can be written in multiple programming languages like C#, JavaScript, Jav
2 min read
How to Reset Form using jQuery with reset() Method? Reset a form means clear all input fields data and returns to their initial default values. It can be useful where a user wants to clear all entered data or you want to reset the form after a successful submission. The reset() method can easily reset the form data after clicking the reset button or
3 min read
How to Redirect to Another Page After 5 Seconds using jQuery ? In this article, we will learn, how to redirect to another page or URL after a specified time in jQuery. The built-in function used for performing the action is as follows. The setTimeout(callback, delay) function takes two parameters a callback and a time in milliseconds. When this method is called
1 min read
jQuery UI Tabs refresh() Method jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Tabs widget is used to create a single content area with multiple panels that are associated with a header in a list. T
3 min read