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






4.20/5 (4 votes)
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(“content”, “7200”); //1 hour
}
</script>
Or:
<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.
- Remove the code of
<meta>
tag (<meta id="metaAutoRefresh" http-equiv="refresh" content="300">
) from page. - 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
IdchkSelect
:Checkbox
Id
- Call
onClickCheckbox
function on click ofcheckbox
.