<body id="container" onload="javascript:abc()">
<script type="text/javascript">
function abc(){
setTimeout(function () {
location.reload();
}, 1000);
}
</script>
The above function works fine with all the browsers and page is refreshed after one second but get the page blink after every page refresh.
Is there any way to avoid page blink only with javascript ?
<body id="container" onload="javascript:abc()">
<script type="text/javascript">
function abc(){
setTimeout(function () {
location.reload();
}, 1000);
}
</script>
The above function works fine with all the browsers and page is refreshed after one second but get the page blink after every page refresh.
Is there any way to avoid page blink only with javascript ?
Share Improve this question asked Jun 27, 2017 at 9:15 sagar patilsagar patil 471 gold badge1 silver badge6 bronze badges 2- 2 Dont reload the page... Use AJAX to update just the data... – Jonas Wilms Commented Jun 27, 2017 at 9:17
- You are basically asking the browser to reparse DOM, re-apply the CSS and re-interpret all the JS instantly? I don't think the tech's there yet. – iuliu Commented Jun 27, 2017 at 13:04
2 Answers
Reset to default 3 <script type="text/javascript">
setInterval(abc, 1000);
function abc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("container").innerHTML = this.responseText;
}
};
xhttp.open("GET", "notify.asp", true);
xhttp.send();
}
</script>
<body id="container" onload="javascript:abc()">
This works perfect for me
In short, no.
You're refreshing a page, so making the browser go and get everything again. The reason it's quicker and blinking, instead of loading is because all the data is cached.
What you might be able to do is change the way you're doing things. Why do you need to refresh the page every second? If it's to get new, updated data, look into ajax.