HTML and CSS Reference
In-Depth Information
the ad experience altogether. I see this API being extremely useful in the very near future as browsers implement the
API. For more information on this API, visit http://w3.org/TR/netinfo-api .
Vibration API
Another useful mobile device API is the Vibration API, which allows for JavaScript to control the device's vibration
hardware (if available). By calling on the vibrate method, you can trigger notifications to a user's mobile device,
outlined in the following code snippet:
<script>
var duration = 2000;
var delay = 500;
navigator.vibrate([duration, delay, duration]);
</script>
In the previous example, you set the device to vibrate for two seconds and then wait half a second and then
vibrate again for two seconds. If the vibration is not allowed on the device, the calls to vibrate will simply be ignored.
For more information on the Vibration API, visit http://w3.org/TR/vibration .
Calendar API
The Calendar API allows for universal access to a user's calendar. The API can be used to create, retrieve, update, and
remove calendar event information from a user's calendar, which could be really beneficial if your client has a huge
sale and wants to send a calendar invite to their users from within an ad unit. Through the navigator object, you can
grab a reference to the user's calendar, which you can create, retrieve, and manipulate events. For more information
on this API, visit http://w3.org/TR/calendar-api .
Contacts API
Taking what you've just learned from the Web Intents API, you can use this to pull in a user's contact list on their
device directly within the advertisement (opt-in). Listing 12-14 shows how to use the Web Intents API to gain access to
your contact list.
Listing 12-14. Contacts API Example
var intent = new Intent({
action:" http://webintents.org/pick ",
type:" http://w3.org/type/contact ",
extras:{fields: ["displayName", "emails"] }
});
navigator.startActivity(intent, contactsOK, contactsFail);
function contactsOK (contacts) {
console.log(contacts);
}
function contactsFail (error) {
console.error(error);
}
 
Search WWH ::




Custom Search