WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to refresh a page with jQuery

Topic: JavaScript / jQueryPrev|Next

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. However, if it is false (which is default) or not specified, the browser may reload the page from its cache.

  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="utf-8">
  • <title>Reload the Page Using jQuery</title>
  • <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  • <script type="text/javascript">
  •     $(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 type="text/javascript">
  •     function reloadPage(){
  •         location.reload(true);
  •     }
  • </script>
  • </head>
  • <body>
  •     <button type="button" onclick="reloadPage();">Reload page</button>   
  • </body> 
  • </html>

Related FAQ

Here are some more FAQ related to this topic:

Your Feedback:

We would love to hear from you, please drop us a line.