in JavaScript
my code is like that
开发者_C百科var orientation = window.orientation
alert(orientation)
I'm getting orientation as undefined
In Chrome at least this is a bug. I was looking into it today and raised a bug https://code.google.com/p/chromium/issues/detail?id=181136 that you can track to see if and when it changes.
In the mean time, you can use window.matchMedia and media queries to determine the orientation. See http://jsbin.com/efuhud/1 for a demo.
I would expect it to be inline with the other orientation events that fire in WebKit. Interestingly in Chrome Devtools, if you Override the orientation (fliping the resolution) all the other media query events fire.
It works when I test it on a device which supports orientation.
Presumably your test suite does not include such a device, so the value of the property is undefined unless explicitly set to something.
Might this help you out...!!!
var orientation= (window.orientation !=undefined);
alert(orientation);
精彩评论