0

Here is the case.

I have a website built in asp.net mvc3 with custom CMS.

Is there any way by clicking a button from cms to reload the page of the website visitors?

For example, here in stackoverflow, if an admin from the backend pressed a button my page would reload automatically (or even a lightbox would appear, or redirect me to a different page).

Can we do that?

2 Answers2

0

With HTML5 you can use web workers to do this for you: http://html5demos.com/worker

Without HTML5, you can set up some basic polling code in your javascript. It would call a method on the server that would tell it whether or not to reload. You can run this every 30 seconds let's say:

$(document).ready(function(){
    var doRefresh = function(){
        $.get('checkForRefresh', function (data) { ... handle response ... });
    };
    setInterval(doRefresh, 30000);
});

And then just have your checkForRefresh server side code read a value set by that CMS button.

Milimetric
  • 13,411
  • 4
  • 44
  • 56
0

Forcing a reload on a button click boils down to something like this (using jQuery and javascript):

<script type="text/javascript">
    $(document).ready(function() {
        $('#Button1').click(function() {
            location.reload();
        });
    });     
</script>

The first answer on the following question shows two ways to refresh the page, one forcing a reload like above, and the second, much like @Milimetric describes in his answer: Refresh (reload) a page once using jQuery?.

Community
  • 1
  • 1
Sergi Papaseit
  • 15,999
  • 16
  • 67
  • 101