views:

1371

answers:

4

Does the iPhone browser have special events that I can hook into with Javascript? For instance, if the users slides to the left, I would like to perform a certain action. If there are events like this available, it would be nice to see a reference for all of them. ideally, there will someday be a standard for all touch-screen mobile browsers.

A: 

Do you really mean "when the device orientation changes", perhaps? If so, you may want to bind to the onorientationchange event.

There's a useful reference of all on* events at Apple's Safari Reference Library.

codehead
Yes, orientationchange would be one such event that I would like to handle. That web page is quite useless though, becase I am unable to scroll it!
Josh Stodola
Seriously... try to scroll that page in IE. It's insane.
Josh Stodola
+5  A: 

You can access multi-touch events and gestures, but there is a fair amount of under-the-hood plumbing you'll likely have to handle yourself. Here is Apple's guide:

http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html

As an example of what can be done with a MobileSafari web app, check out this article on Apple's in-house "PastryKit":

http://daringfireball.net/2009/12/pastrykit

Particularly, you can use Safari on Windows or Mac (if you enable the developer menu in the preferences and set the useragent to MobileSafari 3.x) and check out the way it works.

Another UI library to look at is jQTouch:

http://www.jqtouch.com/

Frank Schmitt
A: 

Perhaps the onscroll, ontouchstart, ontouchmove, or similiar events are what you're looking for. All listed on the Safari HTML Reference page.

philfreo
+1  A: 

jQTouch really does the thing. http://jqtouch.com

http://code.google.com/p/jqtouch/wiki/CallbackEvents

myfreeweb