Filed under: Developer, iPhone
iPhone Orientation: Apple Sample Code
Apple has posted sample code demonstrating how to handle iPhone or iPod touch orientation events through JavaScript, HTML, and CSS. Whenever an iPhone rotates, it triggers orientation events that you can catch in Mobile Safari. Apple provides a sample iPhoneOrientation.js file that implements a typical handler, window.onorientationchange. CSS attributes can dynamically change how the webpage appears.
I loaded a copy of the sample over at my website. If you'd like to give it a try on your iPhone, navigate here.
Thanks, syd

Get a WordPress.com Blog
![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 1)
Brian said 3:25PM on 12-20-2007
So how long before we have an iPhone version of MacSaber?
Reply
Brandon Crawford said 3:50PM on 12-20-2007
Not anytime soon. This is literally ONLY to convey the information of whether the screen is held portrait or landscape.
JRob said 3:35PM on 12-20-2007
cool... but no detection for upside-down (home button on the top)?
Reply
Codey H. said 3:49PM on 12-20-2007
Nice precursor to the SDK hopefully.
Reply
Sketch said 4:57PM on 12-20-2007
It might be helpful to know that it maintains its previous orientation when navigating away and then back, as in, if I click one of the links in Portrait mode, turn the phone to landscape, and push 'Back', the first page still thinks it's in portrait.
Reply
Gregg said 5:24PM on 12-20-2007
macsaber has been out for a while, search for isaber
Justin Garrity said 7:03PM on 12-20-2007
Using this code, my friend Nathan and I put together this nice iPhone Snow Globe.
http://www.iPhoneSnowGlobe.com
Happy Holidays!
Justin
Reply
Think Adrian said 2:33AM on 12-21-2007
I don't understand how this is new? Didn't Apple post some kind of web API when the iPhone was launched?
Reply
DVD to iPhone said 9:37PM on 12-26-2007
http://ripdvdtomp4.tumblr.com/
Reply
Maite said 12:03PM on 12-22-2007
You can also do the same thing with Jiggy (http://www.jiggyapp.com). It lets your application receive accelerometer events, among many other cool things.
Reply