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













Reader Comments (Page 1 of 1)
12-20-2007 @ 3:25PM
Brian said...
So how long before we have an iPhone version of MacSaber?
Reply
12-20-2007 @ 3:50PM
Brandon Crawford said...
Not anytime soon. This is literally ONLY to convey the information of whether the screen is held portrait or landscape.
12-20-2007 @ 3:35PM
JRob said...
cool... but no detection for upside-down (home button on the top)?
Reply
12-20-2007 @ 3:49PM
Codey H. said...
Nice precursor to the SDK hopefully.
Reply
12-20-2007 @ 4:57PM
Sketch said...
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
12-20-2007 @ 5:24PM
Gregg said...
macsaber has been out for a while, search for isaber
12-20-2007 @ 7:03PM
Justin Garrity said...
Using this code, my friend Nathan and I put together this nice iPhone Snow Globe.
http://www.iPhoneSnowGlobe.com
Happy Holidays!
Justin
Reply
12-21-2007 @ 2:33AM
Think Adrian said...
I don't understand how this is new? Didn't Apple post some kind of web API when the iPhone was launched?
Reply
12-22-2007 @ 12:03PM
Maite said...
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
12-26-2007 @ 9:37PM
DVD to iPhone said...
http://ripdvdtomp4.tumblr.com/
Reply