Q:

Is there any way to refresh the page only for specific times in jquery

I am using jquery to reload a page with the below code
<script type="text/javascript">
  $(document).ready(function(){
       setInterval(function() {
              window.location.reload();
                }, 10000); 
  })
</script>

But i had some requirement, that i need to refresh the page only for 6 times, and display a message that "Something problem occurred"
So how to refresh/reload a page only for specific times(6 in my case) using jquery ?

A:

Just an idea: you can use query string to pass the counter between page refreshes. Something like this: 
<script type="text/javascript">
  var counter = 0;
  $(document).ready(function(){
       counter = parseInt(getParameterByName("counter"));
       if(counter < 6){
       setInterval(function() {
              window.location.href = "http://" + window.location.host + window.location.pathname + '?counter=' + (counter + 1);
                }, 10000); 
       }
  })

//convenient method to get parameters from query string 
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
</script>

A:

Based on the comment of LShetty:
A basic example of using localStorage could be seen here http://coding.smashingmagazine.com/2010/10/11/local-storage-and-how-to-use-it/
E.g. something along the lines
<script type="text/javascript">
  $(document).ready(function(){
       var counter = localStorage.getItem('counter');
       if (counter == null) {
         counter = 0;
       }
       counter++;
       if (counter<=6) {
         localStorage.setItem('counter', counter);
         setInterval( function() {
                         window.location.reload();
                      }, 10000 );
       }
  })
</script>

Of course you could use a cookie for the same purpose, as you are going to store just a counter (way bellow the 4K limit of data stored in a cookie). For example you could utilize the createCookie and readCookie functions from the following article http://www.quirksmode.org/js/cookies.html

