Detecting Device Orientation Change in Javascript

Easy orientation change detection for Ionic Apps or mobile web apps.

window.addEventListener("orientationchange", 
    function() {
        if (window.orientation == 90 || window.orientation == -90) {
            alert('landscape mode');
        } else {
            alert('portrait mode;);
        }
    }, false);