Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 10: Handling Touch Interactions ... > Detecting an Orientation Change


One of the unique events that an iPhone web application developer needs to be able to trap for is the change between vertical and horizontal orientation. Safari on IOS provides support for the orientationchange event handler of the window object. This event is triggered each time the device is rotated by the user.

TRY IT OUT: Detecting an Orientation Change

For a demonstration of how to detect an orientation change in your app, follow the steps below.

1. Create the following HTML document in your text editor and then save the document as BIDHJ-Ch10-Ex2.html.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html >
<title>Orientation Change Example</title>
<meta name="viewport" content="width=320; initial-scale=1.0;
   maximum-scale=1.0; user-scalable=0;">
<body onload="orientationChangeHandler();"
<h4 id="mode">Ras sed nibh.</h4>
Donec semper lorem ac dolor ornare interdum. Praesent condimentum.
Suspendisse lacinia interdum augue. Nunc venenatis ipsum sed ligula.
Aenean vitae lacus. Sed sit amet neque. Vestibulum ante ipsum primis
in faucibus orci luctus et ultrices posuere cubilia Curae; Duis
laoreet lorem quis nulla. Curabitur enim erat, gravida ac,


You are currently reading a PREVIEW of this book.


Get instant access to over $1 million worth of books and videos.


Start a Free Trial

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint