How To Reload/Refresh A Page Using Javascript In Addition To Jquery

Advertisement

Masukkan script iklan 970x90px

How To Reload/Refresh A Page Using Javascript In Addition To Jquery

Jumat, 26 Februari 2021

JavaScript provides several ways to reload or refresh an HTML page exactly the criterion way to practice this task is yesteryear using window.location object. This object provides a reload() method which instructs the browser to reload the page. The browser tin mail away practice it from its cache or from the server, which depends upon optional parameter i.e. reload(true) volition reload the page from the server exactly reload(false) volition solely reload the page from browser's cache, which may or may non correspond the electrical flow version at the server.


You tin mail away combine both jQuery as well as JavaScript to wrap the page refresh code every bit shown inwards our example. Btw, this is non the solely way to refresh a page inwards JavaScript, you lot tin mail away too utilisation history.go(0) as well as location.replcace(locatoin.pathname) to reload the page.


JavaScript as well as jQuery instance to reload a page 

In this example, I volition nation you lot how to reload a page from both server as well as browser's cache using jQuery as well as JavaScript. In our HTML nosotros accept 2 buttons, i for reloading page from the server as well as other from refresh page from browser's cache. Though location.reload() volition piece of occupation inwards all browser, you lot tin mail away too utilisation jQuery to wrap other code e.g. attaching a click handler to the 2 buttons.


Here is the amount instance for your reference:

<html> <head> <title>How to reload/refresh a page using jQuery</title> </head>  <body>  <h2>Reloading a page using jQuery as well as JavaScript</h2>  <button id="btn_reload">Reload from Server</button> <button id="btn_refresh">Reload from Browser's cache</button>  <script src="//code.jquery.com/jquery-1.6.2.min.js"></script> <script> $(document).ready(function() {  $("#btn_refresh").click(function(){ location.reload(false); //loads from browser's cache   });  $("#btn_reload").click(function(){ location.reload(true); //loads from server  });  }); </script>  </body> </html> 



That's all nearly how to reload or refresh a page inwards jQuery using JavaScript. Just shout out upwards that window.location.reload() volition teach the browser to reload the page, which agency downloading information from the server, parsing, as well as displaying it. You tin mail away too reload a page from browser's cache yesteryear using the location.reload(false) method. You tin mail away read to a greater extent than nearly jQuery methods on jQuery inwards Action book, i of the best resources to larn as well as utilisation jQuery inwards existent basis projects.

Other jQuery articles for you
  • 5 Books to larn jQuery for Web developers (books)
  • How to acquire electrical flow URL, Parameters, as well as Hash using jQuery? (solution)
  • jQuery Hello World Example (program)
  • How to utilisation to a greater extent than than i jQuery UI DatePicker inwards JSP page? (example)
  • How to practice tab-based UI using jQuery? (example)
  • How to alter to a greater extent than than i chemical component subdivision inwards i line? (example)
  • How to redirect a page URL using jQuery as well as JavaScript? (solution)
  • How to write HelloWorld inwards jQuery? (solution)
  • 20 jQuery Interview Questions for Java Web Developers (list)
  • How to charge jQuery inwards a spider web page? (solution)



Further Reading
The Complete jQuery Course: From Beginner To Advanced!
Up as well as Running amongst jQuery
jQuery Fundamentals By Dan Wahlin

Thanks for reading this article. If you lot similar this tutorial as well as then delight part amongst your friends as well as colleagues. If you lot accept whatever enquiry or feedback as well as then delight driblet a comment.