window reload in only 767 screen

Window Reload in Only 767 Screen

If you want to reload the window only when the screen size is 767px or below, you can use the following code:


if(window.innerWidth <= 767) {
  location.reload();
}

This code checks the width of the window and if it is less than or equal to 767px, it reloads the page using the location.reload() method.

If you want to do this using jQuery, you can use the following code:


$(window).resize(function() {
  if($(window).width() <= 767) {
    location.reload();
  }
});

This code attaches a resize event to the window and checks the width of the window on every resize. If the width is less than or equal to 767px, it reloads the page using the location.reload() method.

Another way to do this is by using media queries in CSS. You can add the following CSS code to your stylesheet:


@media (max-width: 767px) {
  body:after {
    content: '';
    display: none;
    /* Reload CSS file */
    background-image: url('path/to/your/css/file.css');
  }
}

This code uses a media query to apply styles only when the screen size is 767px or below. It adds a pseudo-element to the body and sets its display to none. Then, it reloads the CSS file by changing its background-image property. This will cause the browser to reload the CSS file and apply any changes made to it.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe