Android Browser Triggers jQuery $(window).resize() on scrolling Android Browser Triggers jQuery $(window).resize() on scrolling android android

Android Browser Triggers jQuery $(window).resize() on scrolling


I was having the same problem, my solution was to check if the window size actually changed, for doing it I needed to store the past window width somewhere in my app. The code could be something like this:

$(window).resize(function() {  clearTimeout(app.resize.timer)  app.resize.timer = setTimeout(function(){     var window_changed = $(window).width() != app.size.window_width     if(window_changed) console.log('Window size changed! resize site')  }, 500)               })

I did not count on the window height because my Android browser hides and shows the address textbox when I scroll down the site making the window height change on vertical scroll


@john-mccollum is correct in the comments. It appears to be the disappearing browser interface causing a change in height that triggers the resize event. So check for change in width specifically in your function if you are doing responsive design stuff where you want to check if the width has been resized.

$(window).resize(function(){    var w = $(window).width();    if (typeof checkw == 'undefined') checkw = w;    if (w!=checkw) {        console.log("The width changed from "+checkw+" to "+w);        // do your responsive magic!        checkw = w;    }});

Not required to make this work, but this pairs well with the Paul Irish / John Hann "smartresize" method.


i'm having the same problem too!
the problem is true because the height of the browser in Android will change when the url bar hide and show. So, we have to make the browser reload only happens when the width size changes.

i saw this question in Stackoverflow show me how to do this. And this is the jsfiddle.

      var doit;      function resizedw(appwidth){          var window_changed = $(window).width() != appwidth;          if ($(window).width() != appwidth){            ("body").append("did it"+appwidth+" ");          }          past_width = $(window).width();      }      var past_width = $(window).width();      window.onresize = function() {        clearTimeout(doit);        doit = setTimeout(function() {            resizedw(past_width);        }, 100);      };