Friday, December 21, 2012

Reload / Refresh web page using Javascript and jQuery

There are several ways to refresh a page using a button and javascript action.

.
<input onclick="history.go(0)" type="button" value="Reload Page" />


2.
<input onclick="window.location.reload" type="button" value="Reload Page" />

3.
<input onclick="window.location.href=window.location.href" type="button" value="Reload Page" />
One could also use jQuery datatable buttons for various actions. A simple "Refresh" button reloads the page in this case.
$(document).ready(function() {
 var oTable = $('#myTable').dataTable({
  "sDom" : 'T<"clear">lfrtip',
  "oTableTools" : {
   "aButtons" : [ {
    "sExtends" : "copy",
    "sButtonText" : "Copy"
   }, {
    "sExtends" : "xls",
    "sButtonText" : "XLS"
   }, {
    "sExtends" : "text",
    "sButtonText" : "Refresh",
    "fnClick": function ( nButton, oConfig, oFlash ) {
      javascript:window.location.reload(); 
   }} ]
  }
 });

No comments:

Post a Comment