Search code examples
javascripthtmltextwindowresolution

Block certain screen resolutions from viewing website?


Is it possible to somehow block certain computers from viewing website via screen resolution?

The way I was thinking of doing it would be using var a = window.screen.height and var b = window.screen.width then doing <pre id=res></pre> with document.getElementById("res").textContent=b+" x "+a; and now the part I need help with... How would I make it so that if res.textContent=1234 x 1234 then allow, but else redirect... Send help!

-gr3uh


Solution

  • I figured out a way to solve my question, Thanks for the feedback anyway, turns out I just needed to make a script like so...

    var screenSizeIn = screen.width + " X " +
      screen.height;
    
    console.log("Screen size is: " + screenSizeIn);
    if (screenSizeIn == "1280 X 720") { // <-- good screen size
      console.log("Screen size is good!");
    } else { // <-- bad screen size
      window.location = "/blocked.html"; // <-- what to do when wrong
      console.log("Screen size is wrong!");
    }