<label for="unchecked" style="padding: 10px 24px 10px 0"> 1 minutes refresh </label>
@Html.EJS().Switch("unchecked").Change("setRe").EnablePersistence(true).Render()
<script type="text/javascript">
var interval;
//To relod the page based on setinterval.
function doit() {
clearInterval(interval);
if (window.location.reload)
window.location.reload(true);
}
//Will trigger on page reload.
function reloadpage() {
//To get the instance of switch component
var instance = ej.base.getComponent(document.querySelector("#switch"), 'switch');
if (instance.checked) {
interval = setInterval(doit, 60000);
}
}
//This function will trigger while changing state in switch.
function setRe(val) {
if (val.checked) {
interval = setInterval(doit, 60000);
}
else {
clearInterval(interval);
}
}
onload = reloadpage;
</script> |
<label for="switch" style="padding: 10px 24px 10px 0"> 1 minutes refresh </label>
@Html.EJS().Switch("switch").Change("setRe").EnablePersistence(true).Render()
<script type="text/javascript">
//..
//Will trigger on page reload.
function reloadpage() {
//To get the instance of switch component
var instance = ej.base.getComponent(document.querySelector("#switch"), 'switch');
if (instance.checked) {
interval = setInterval(doit, 60000);
}
}
//..
</script>
|