I am attaching a listener to the orientationchange event:
window.addEventListener(\'orientationchange\', function () {
console.log(window.innerHeight);
}
Gajus' and burtelli's solutions are robust but the overhead is high. Here is a slim version that's reasonably fast in 2017, using requestAnimationFrame:
// Wait until innerheight changes, for max 120 frames
function orientationChanged() {
const timeout = 120;
return new window.Promise(function(resolve) {
const go = (i, height0) => {
window.innerHeight != height0 || i >= timeout ?
resolve() :
window.requestAnimationFrame(() => go(i + 1, height0));
};
go(0, window.innerHeight);
});
}
Use it like this:
window.addEventListener('orientationchange', function () {
orientationChanged().then(function() {
// Profit
});
});