1

How to refresh the page once when after resized window to less than 767px ?

I tried many examples, but it does not working well.

$(document).ready(function(){

    if ($(window).width() < 767) {   

             location.reload();  // refresh page 

    }
    else {  

            // width more than 768px for PC  

    }
}); 

Please help~

user3758718
  • 131
  • 1
  • 2
  • 12
  • 1
    `window.location.reload()` maybe? But wouldn't that give an infinite loop of reloads? In what browser are you testing? – putvande Jul 15 '14 at 08:23
  • I'd link to this anyway: http://stackoverflow.com/questions/641857/javascript-window-resize-event – George G Jul 15 '14 at 08:52

2 Answers2

3
$(document).ready(function(){
$(window).on('resize',function(){
    if ($(window).width() < 767) {   
      location.reload();  // refresh page 
    }
    else {  
      // width more than 768px for PC  
    }
}); 
});
RGS
  • 5,131
  • 6
  • 37
  • 65
0

if dont want to hit the reload to early, you could delay like so:

$(document).ready(function() {
    $(window).on("resize", function() {
        var tm;
        clearTimeout(tm);
        tm = setTimeout(function() {
            if ($(window).width() < 767) {
                location.reload();  // refresh page 
            }
            else {
                // width more than 768px for PC  
            }
        }, 100);
    });
});
reyaner
  • 2,799
  • 1
  • 12
  • 17