treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Reload page when browser hits a specific width

  • Hey, does anyone know how to reload a page when the browser hits 768px? Right now I am using a code that reloads the page when the width is changed to anything but I only need it to reload when it hits specific widths.

    Thanks!

  • I'm not sure why you would want to do this, and it seems like bad practice, but here's how you could do this with jQuery:

    $(window).on("resize", function() {
      var w = $(this).width();
      if ( w === 768 ) {
        location.reload();
      }
    });
    
  • JoshBlackwood, thanks for the help...I figured it would be bad practice so ill look into my code and try to find out whats causing the problem.

  • @mdyorke,

    Hey, what is the problem and conditions for it? For what purpose does it need to 'reload'? There could be a totally different solution.