screentype = screen.orientation.type.match(/\w+/)[0]; console.log(screentype); if(screentype == "portrait") { alert("Please view in landscape view. rotate your phone"); }