Loading...

TapGen

Free online tutorials

img

Reloading a page using jQuery allows you to reload the current web page. this article will guide you step-by-step.

You can use the location.reload() method to refresh a web page using jQuery. by clicking the refresh button on the web page you can do that.

How to refresh a page using jQuery/javascript?


Let's check out an example of location.reload() method. 

Example: Refresh the page when a button with the id "refreshButton" is clicked. 

                                        
 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Page Refresh Example</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            $('#refreshButton').click(function() {
                // Reload the current page
                location.reload();
            });
        });
    </script>
</head>
<body>
    <button id="refreshButton">Refresh Page</button>
</body>
</html>
 
                                    

In this example when you click the Refresh Page button the current page reloads.

Force Reload: To ensure the page is reloaded from the server and not from the cache, you might have seen location.reload(true);

 
                                            $(document).ready(function() {
    // Example: Refresh the page when a button with id "refreshButton" is clicked
    $('#refreshButton').click(function() {
        // Reload the current page
        location.reload(true);
    });
});
 
                                    

How do I refresh a page using JavaScript?

To refresh a web page using JavaScript, you can use the same location.reload() method. it will refresh the page when a button is clicked.

                                        
   <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Page Refresh Example</title>
<script>
    function reloadPage(){
        location.reload(true);
    }
</script>
</head>
<body>
    <button type="button" onclick="reloadPage();">Reload page</button>   
 
</body>
</html>

You don't need any jQuery If you want to reload the page when a button is clicked, you can use HTML and JavaScript.

Thanks

 

=================================
Share This Article
icon

New to Communities?

Join the community