Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

initial window.orientation always 0 on Windows Phone

I'm trying to detect device orientation on my website.

Orientation value seems to be ok after orientationchange event.

$(window).on("orientationchange",function(event){alert(window.orientation);}) 

However problem is initial window.orientation value at page startup which is always 0 even when device is in landscape position.

$(document).ready(function(){alert(window.orientation);});

It doesn't change after some delay (i've checked that) it changes to right value only after orientationchange event.

Is there any way to get proper orientation at page startup?

like image 917
el vis Avatar asked Jul 02 '15 08:07

el vis


1 Answers

It looks like that property isn't actually supported in anything other than chrome for android: https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation

Depending on what it is you want to do you could use CSS rules?

@media only screen and (max-width: 999px) {
  /* rules that only apply for canvases narrower than 1000px */
}

@media only screen and (device-width: 768px) and (orientation: landscape) {
  /* rules for iPad in landscape orientation */
}

@media only screen and (min-device-width: 320px) and (max-device-width:    480px) {
  /* iPhone, Android rules here */
}
like image 50
Siada Avatar answered Nov 04 '22 12:11

Siada