Skip to content

Instantly share code, notes, and snippets.

@marioangulo
Created September 16, 2014 19:03
Show Gist options
  • Save marioangulo/b0f5357d430167d00c6c to your computer and use it in GitHub Desktop.
Save marioangulo/b0f5357d430167d00c6c to your computer and use it in GitHub Desktop.
Redirect Based of Screen Size
function determineIfSmallSize(redirect_url) {
// Detect pixel ratio for true resolution
window.dpr = 1;
if(window.devicePixelRatio !== undefined) {
window.dpr = window.devicePixelRatio;
}
// Screen orientation - innerWidth and innerHeight works for any device and its orientation, including desktops
window.screenOrientation = ((window.innerWidth) > (window.innerHeight)) ? 'landscape' : 'portrait';
// Have to flip width and height in landscape orientation
if (window.screenOrientation == 'portrait') {
window.screenWidth = window.screen.width * window.dpr;
window.screenHeight = window.screen.height * window.dpr;
} else {
window.screenWidth = window.screen.height * window.dpr;
window.screenHeight = window.screen.width * window.dpr;
}
// Set width and height for display purposes
window.trueScreenWidth = window.screen.width * window.dpr;
window.trueScreenHeight = window.screen.height * window.dpr;
window.pixelScreenWidth = window.screen.width;
window.pixelScreenHeight = window.screen.height;
if((window.trueScreenWidth <= 767 || window.trueScreenHeight <= 767) && (redirect_url !== undefined)) {
window.location.href = redirect_url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment