jquery - Refresh the page on a browser resize using JavaScript when difference is more than 100px -


i have code website jquery refresh page on browser resize works fine sensitive on mobile devices. shoud add margin of error. how tu use code when difference in browser width more 100px if browser width smaller , larger

//refresh page on browser resize  $(window).bind('resize', function(e)  {    if (window.rt) cleartimeout(window.rt);    window.rt = settimeout(function()    {      this.location.reload(false); /* false page cache */    }, 200);  });

i'm assuming "when difference in browser width more 100px" means you're attempting detect window has changed in size more 100px. you'll need store original width of window , compare against that:

var originalwidth = $(window).width(); $(window).bind('resize', function(e) {   if (window.rt) cleartimeout(window.rt);   window.rt = settimeout(function() {     if (math.abs($(window).width() - originalwidth) > 100) {       this.location.reload(false); /* false page cache */     }   }, 200); }); 

(this seems odd requirement, however: refreshing page on window resize far ideal ux. may find better use css breakpoints, or scripting if necessary, modify page in place rather brute-force approach of reloading whole thing.)


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -