I am trying to accurately capture the height and width of the mobile browser window when changing the orientation, but (on Android, I am testing) - when the orientation listener is launched and the function is called to capture the window height and width, the new size has not been accurately reflected yet, so I have to call arbitrary delay to get things to register their correct size. How can I handle this? Here is my code:
window.addEventListener(orientationEvent, function() {
setTimeout("setViewport()", 500);
}, false);
function setViewport() {
viewportW = window.innerWidth;
viewportH = window.innerHeight;
}
source
share