DEV Community

keshavs759
keshavs759

Posted on

Refresh Your webpage on window width change using Javascript

you can refresh your webpage when you change the width of your browser using following logic,

<!DOCTYPE html>
<html lang="en">
<head>
  <title>refresh</title>
</head>
<body>

  <script>

var prev_width = window.innerWidth;

function reportWindowSize() {
  var new_width = window.innerWidth;
  if(prev_width!==new_width){
    window.location = window.location;
  }
}

window.onresize = reportWindowSize;

    </script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Discussion (0)