admin管理员组

文章数量:1025539

I'm having a problem about the blinking of the page for my auto-refresh of the page function. Is there a way to make my this blinking of the said page begone? Here's my code:

<script type="text/javascript">
    function refreshPage() { location.reload(); }
    $(document).ready(function () {
       setInterval('refreshPage()', 5000);
    });
</script>

Thanks.

I'm having a problem about the blinking of the page for my auto-refresh of the page function. Is there a way to make my this blinking of the said page begone? Here's my code:

<script type="text/javascript">
    function refreshPage() { location.reload(); }
    $(document).ready(function () {
       setInterval('refreshPage()', 5000);
    });
</script>

Thanks.

Share Improve this question edited Sep 16, 2013 at 9:51 Sahil Mittal 20.8k12 gold badges68 silver badges91 bronze badges asked Sep 16, 2013 at 9:19 Mr.Bobo HahaMr.Bobo Haha 1411 gold badge2 silver badges16 bronze badges 3
  • You can open your page in an iframe and then reload that iframe. – Gupta.Swap Commented Sep 16, 2013 at 9:22
  • iframe?? how can i achieve that sir... – Mr.Bobo Haha Commented Sep 16, 2013 at 9:25
  • 1 Ok, I think i misunderstood your question. If you are trying to add server updates as facebook, then try using some server push technologies like APE(ape-project) – Gupta.Swap Commented Sep 16, 2013 at 9:29
Add a ment  | 

1 Answer 1

Reset to default 2

You probably don't want to refresh the entire page. E.g. logo, menu would stay, while a content somewhere will refresh. I would mark this content with e.g. a div:

<div id="content">
    <!-- stuff in here is to be periodically refreshed -->
</div>

Then, I would add a server-side URL to create just that refreshable content. This depends of course on your server-side technology, but it is probably trivial. Say this URL is http://yourserver/path/to/page/content.

Then with jQuery:

$(document).ready(function () {
    setInterval(function() {
        $("#content").load("http://yourserver/path/to/page/content");
    }, 5000);
});

This is the principle of operation, you may adjust the details. See $.load. This will greatly eliminate the blink.

I'm having a problem about the blinking of the page for my auto-refresh of the page function. Is there a way to make my this blinking of the said page begone? Here's my code:

<script type="text/javascript">
    function refreshPage() { location.reload(); }
    $(document).ready(function () {
       setInterval('refreshPage()', 5000);
    });
</script>

Thanks.

I'm having a problem about the blinking of the page for my auto-refresh of the page function. Is there a way to make my this blinking of the said page begone? Here's my code:

<script type="text/javascript">
    function refreshPage() { location.reload(); }
    $(document).ready(function () {
       setInterval('refreshPage()', 5000);
    });
</script>

Thanks.

Share Improve this question edited Sep 16, 2013 at 9:51 Sahil Mittal 20.8k12 gold badges68 silver badges91 bronze badges asked Sep 16, 2013 at 9:19 Mr.Bobo HahaMr.Bobo Haha 1411 gold badge2 silver badges16 bronze badges 3
  • You can open your page in an iframe and then reload that iframe. – Gupta.Swap Commented Sep 16, 2013 at 9:22
  • iframe?? how can i achieve that sir... – Mr.Bobo Haha Commented Sep 16, 2013 at 9:25
  • 1 Ok, I think i misunderstood your question. If you are trying to add server updates as facebook, then try using some server push technologies like APE(ape-project) – Gupta.Swap Commented Sep 16, 2013 at 9:29
Add a ment  | 

1 Answer 1

Reset to default 2

You probably don't want to refresh the entire page. E.g. logo, menu would stay, while a content somewhere will refresh. I would mark this content with e.g. a div:

<div id="content">
    <!-- stuff in here is to be periodically refreshed -->
</div>

Then, I would add a server-side URL to create just that refreshable content. This depends of course on your server-side technology, but it is probably trivial. Say this URL is http://yourserver/path/to/page/content.

Then with jQuery:

$(document).ready(function () {
    setInterval(function() {
        $("#content").load("http://yourserver/path/to/page/content");
    }, 5000);
});

This is the principle of operation, you may adjust the details. See $.load. This will greatly eliminate the blink.

本文标签: javascriptis autorefresh is possible in jquery without making the page blink like in facebookStack Overflow