sagar patil
sagar patil

Reputation: 47

how to avoid page blink after page refresh by using setTimeout javascript function?

<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 ?

Upvotes: 1

Views: 10213

Answers (2)

sagar patil
sagar patil

Reputation: 47

   <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

Upvotes: 3

MattJHoughton
MattJHoughton

Reputation: 1118

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.

Upvotes: 2

Related Questions