Sunday, July 22, 2012

Reloading a Page using JavaScript

Ways to reload a page using Java script.

When doing web development if you need to reload / refresh a page using Java script, you can use one of the following three methods.

  1. <script language="javascript" type="text/javascript">
  2.     function ReloadMethod1() {
  3.         window.location.href = window.location.href;
  4.     }
  5.     function ReloadMethod2() {
  6.         window.location.reload();
  7.     }
  8.     function ReloadMethod3() {
  9.         history.go(0);
  10.     }
  11. </script>
  12. <input type="button" value="Reload" onclick="window.location.href=window.location.href" />
  13. <%--Calling Javascript function on button click.--%>
  14. <input type="button" value="Reload" onclick="ReloadMethod2()" />
  15. <input type="button" value="Reload" onclick="window.location.reload()" />
  16.  
  17. <!-- ASP Buttons -->
  18. <asp:Button ID="Button1" runat="server" Text="Reload" OnClientClick="window.location.href=window.location.href" />
  19. <%--Calling Javascript function on button click.--%>
  20. <asp:Button ID="Button2" runat="server" Text="Reload" OnClientClick="ReloadMethod2()" />
  21. <asp:Button ID="Button3" runat="server" Text="Reload" OnClientClick="ReloadMethod3()" />

No comments: