Skip to content

Instantly share code, notes, and snippets.

@mrios
Created March 4, 2016 19:08
Show Gist options
  • Save mrios/70c27c4fac0d76aad560 to your computer and use it in GitHub Desktop.
Save mrios/70c27c4fac0d76aad560 to your computer and use it in GitHub Desktop.
Example in javascript to detect specific resolutions suported
// Portrait
var isPortrait = window.matchMedia("only screen and (max-device-width: 586px) and (orientation : portrait)");
// Mobile detection < 586px : not suported
var isMobileMinor586Landscape = window.matchMedia("only screen and (max-device-width: 585px) and (orientation : landscape)");
// Mobile detection 586 x 320 px
var isMobileBeetween586and640Landscape = window.matchMedia("only screen and (max-device-width: 639px) and (min-device-width: 586px) and (orientation : landscape)");
// Mobile detection 640 x 360 px
var isMobileBeetween640and900Landscape = window.matchMedia("only screen and (max-device-width: 900px) and (min-device-width: 640px) and (orientation : landscape)");
if (isPortrait.matches)
$("body").html("<p>Rote su dispositivo</p>")
else {
if (isMobileMinor586Landscape.matches)
$("body").html("<p>Resolucion no soportada</p>")
else {
if (isMobileBeetween586and640Landscape.matches)
window.location.href = "../586x320";
else {
if (isMobileBeetween640and900Landscape.matches)
window.location.href = "../640x360";
else
console.log("bb detected!, not redirecting")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment