Created
September 16, 2014 19:03
-
-
Save marioangulo/b0f5357d430167d00c6c to your computer and use it in GitHub Desktop.
Redirect Based of Screen Size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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