开发者

Detecting Orientation of Windows Phone

I'm using the JavaScript event onorientationchange and the parameter window.orientation to detect orientation changes and orientation values on my website. This works well with an iPhone and an Android. But a Windows Phone doesn't fire the onorientationchange event and window.orientation is undefined. How I detect orientation changes of Windows Phones?

Th开发者_运维百科anks, Konrad


IE9Mobile doesn't support these events.

If your page is being displayed inside a WebBrowser control within a (silverlight) app then you can detect the orientation change at app level and then invoke scripts on the page to pass this information.

If you're just running in the browser then there is no way to detect orientation changes.


In CSS3 (works well with Mango, I don't know if in classic IE9 Mobile, but probably):

@media screen and (max-width: 480px)
{
/* CSS for Orientation Vertical */
}
@media screen and (min-width: 481px)
{
/* CSS for Orientation Horizontal */
}

Let me know if it worked!


The CSS change is perhaps the best way to detect orientation changes but, if you're like me, and just need a quick and dirty way to find out the current orientation then this'll do the job.

var isLandscape = $(window).width() > $(window).height();

For what it's worth, it seems like the implementation of window.orientation differs on certain platforms so you may need to check what device is being used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜