最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - how to avoid page blink after page refresh by using setTimeout javascript function? - Stack Overflow

programmeradmin5浏览0评论
<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
Add a ment  | 

2 Answers 2

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.

发布评论

评论列表(0)

  1. 暂无评论