Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Stop/Change <meta> Tag Refresh in .NET or Alternative Way to Refresh the Page using JavaScript

0.00/5 (No votes)
20 Oct 2014 1  
Alternative way to refresh the page using JavaScript and not using meta tag of HTML to refresh the page

Introduction

There is no appropriate solution to stop <meta> tag refresh attribute or change the time interval of refresh.

I am using the <meta> tag to refresh the Page in 5 minute time intervals.

<meta id="metaAutoRefresh" http-equiv="refresh" content="300">

Problem

I want to stop the meta tag refresh when I click the checkbox of grid.

Tried but does not work

I have tired so much to solve the problem but can’t. I have tried these lines of code in JavaScript:

Example 1

To remove the <meta> tag:

<script type="text/javascript">
function onClickCheckbox()
{
var mr = document.getElementById("metaAutoRefresh");
mr.parentNode.removeChild(mr);
}
</script> 
Example 2

To change the refresh time interval of <meta> tag:

<script type="text/javascript">
function onClickCheckbox()
{
document.getElementById("metaAutoRefresh").setAttribute(&ldquo;content&rdquo;, &ldquo;7200&rdquo;); //1 hour
}
</script>

Or:

<script type="text/javascript">
function onClickCheckbox()
{
$("#metaAutoRefresh").prop(&ldquo;content&rdquo;, &ldquo;7200&rdquo;); //1 hour
}
</script>

I have tried the above code to solve the stop/change the <meta> tag refresh time interval, but I can’t.

Solution

You can do it with an alternative way using JavaScript.

  1. Remove the code of <meta> tag (<meta id="metaAutoRefresh" http-equiv="refresh" content="300">) from page.
  2. Write the JavaScript code in <head> section of page.
     <script src="~/Scripts/jquery-ui-1.10.3.js"></script>
            <script type="text/javascript">
                    var vRefreshId = null;
                    vRefreshId = setInterval("window.location.reload()", 5*60*1000); //5 min
    
                    function stopRefresh() {
                        clearInterval(vRefreshId);
                    }
                    function startRefresh() {
                    vRefreshId = setInterval("window.location.reload()", 5*60*1000);
                    }
                    function changeRefreshTime(vTimeInterval) {
                    vRefreshId = setInterval("window.location.reload()", parseInt(vTimeInterval));
                    }
    
                   function onClickCheckbox()
                    {
                                    $('#gridClaim tr').each(function () {
                                         if($(this).closest('tr').find
                                         ("input[id='chkSelect']").is(':checked'))
    
                               {
                          stopRefresh();
                          return false;
                        }
                     });
                    startRefresh();
                  }
          </script> 
    • gridClaim: Grid Id
    • chkSelect: Checkbox Id
  3. Call onClickCheckbox function on click of checkbox.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here