Q:

How to refresh a page with jQuery

0

How to refresh a page with jQuery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the JavaScript location.reload() Method

You can simply use the JavaScript location.reload() method to refresh or reloads the page. This method optionally accepts a Boolean parameter true or false.

If the parameter true is specified, it causes the page to always be reloaded from the server. But, if it is false (which is default) or not specified, the browser may reload the page from its cache.

Let's check out an example to understand how this method basically works:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Reload the Page Using jQuery</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            location.reload(true);
        });
    });
</script>
</head>
<body>
    <button type="button">Reload page</button>   
</body> 
</html>

You can also do the same thing with plain JavaScript. You don't need jQuery for this. Check out the following example which is the modified version of the previous example.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Refresh the Page with JavaScript</title>
<script>
    function reloadPage(){
        location.reload(true);
    }
</script>
</head>
<body>
    <button type="button" onclick="reloadPage();">Reload page</button>   
</body> 
</html>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to select an element with multiple classes wit... >>
<< How to change href attribute of a hyperlink using ...