Chapter 15. Device Interaction

Mobile browsers have the useful facility of being able to interact with the device—both the operating system and the hardware. Communication can be driven by URIs used in links or JavaScript APIs. Some specific platforms support both an API and a URI scheme for the same feature; in that case the API usually is the preferred way as it’s more flexible and less error-prone.

Apache Cordova/PhoneGap and some native web platforms add support for more APIs than the ones available in the standard web view on every platform, as we will see later.

Mobile-Specific URIs

There are some URI schemes that many mobile browsers understand that enable us to communicate with some phone features. We can use these URIs in typical a elements, and in some browsers we can use JavaScript to force the URI using location.href.

Usually we are talking about using a protocol name, a colon, and parameters, such as tel:2222:

<a href="protocol:parameters"></a>

<script>
   location.href = "protocol:parameters";
</script>

Note

The Wireless Telephony Application Interface (WTAI), part of the WAP 1.x standard, was created in the last millennium; the WTAI libraries were preinstalled on many phones and can be accessed by other applications, such as the browser. To use these libraries (if available), we used to use the syntax wtai://<library name>/<function name>[(;parameter)*]. Today, only feature phones still support this library.

We need to be careful about using URI schemes that aren’t compatible ...

Get Programming the Mobile Web, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.