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
  • 111
  • 1
  • 2
  • 11

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
  • 4,825
  • 4
  • 29
  • 52
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,779
  • 1
  • 9
  • 15