Click here to Skip to main content
15,903,362 members
Articles / Programming Languages / Javascript
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
4.20/5 (4 votes)
20 Oct 2014CPOL 12.6K   5  
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.

HTML
<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:

JavaScript
<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:

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

Or:

JavaScript
<script type="text/javascript">
function onClickCheckbox()
{
$("#metaAutoRefresh").prop("content", "7200"); //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.
    JavaScript
    <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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --