Skip to Content

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



Categories

Developer iPhone

Apple has posted sample code demonstrating how to handle iPhone or iPod touch orientation events through JavaScript, HTML, and CSS....
 

Add a Comment

*0 / 3000 Character Maximum

10 Comments

Filter by:
Maite

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.

December 22 2007 at 12:02 PM Report abuse rate up rate down Reply
DVD to iPhone

http://ripdvdtomp4.tumblr.com/

December 21 2007 at 5:02 AM Report abuse rate up rate down Reply
Adrian vG

I don't understand how this is new? Didn't Apple post some kind of web API when the iPhone was launched?

December 21 2007 at 2:33 AM Report abuse rate up rate down Reply
Justin Garrity

Using this code, my friend Nathan and I put together this nice iPhone Snow Globe.

http://www.iPhoneSnowGlobe.com

Happy Holidays!

Justin

December 20 2007 at 7:02 PM Report abuse rate up rate down Reply
A strolling player

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.

December 20 2007 at 4:56 PM Report abuse rate up rate down Reply
1 reply to A strolling player's comment
Gregg

macsaber has been out for a while, search for isaber

December 20 2007 at 5:23 PM Report abuse rate up rate down Reply
Codey H.

Nice precursor to the SDK hopefully.

December 20 2007 at 3:49 PM Report abuse rate up rate down Reply
JRob

cool... but no detection for upside-down (home button on the top)?

December 20 2007 at 3:35 PM Report abuse rate up rate down Reply
BJ

So how long before we have an iPhone version of MacSaber?

December 20 2007 at 3:25 PM Report abuse rate up rate down Reply
1 reply to BJ's comment
Brandon Crawford

Not anytime soon. This is literally ONLY to convey the information of whether the screen is held portrait or landscape.

December 20 2007 at 3:48 PM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.