Science Knowings: HTML Course For Social Media

HTML5 Contacts API

From Editing to Contact API

Previously, we explored the HTML5 Editing API, which provided a range of functionality for editing and manipulating HTML content. Today, we embark on a new adventure with the HTML5 Contacts API, which empowers you to access and manage contact data from your web applications.

Welcome to HTML5 Contacts API

The HTML5 Contacts API is a powerful feature that allows web applications to interact with the user's contact list on their device. It provides an easy and standardized way to access, create, edit, and delete contacts, as well as search and sort them.

Why Use HTML5 Contacts API?

The benefits of using the HTML5 Contacts API are numerous:

  • Enhanced user experience: Simplifies and streamlines contact management within web applications.
  • Cross-platform compatibility: Works consistently across different devices and browsers.
  • Improved efficiency: Avoids the need for manual data entry and helps maintain up-to-date contact information.

Getting Started with the API

To use the HTML5 Contacts API, you'll need to request the contacts permission from the user. Once granted, you can access the navigator.contacts object to perform various operations on the contact list.

Example Use Cases

The HTML5 Contacts API can be leveraged for a wide range of use cases:

  • Address book management: Create and maintain a digital address book within your web application.
  • Contact synchronization: Sync contacts between different devices and services.
  • Contact sharing: Facilitate the sharing of contacts via email, social media, or other channels.
  • Customer relationship management (CRM): Enhance CRM systems by integrating contact information from the user's device.

Understanding a Contact Object

A contact object represents a single contact in the user's address book. It consists of various fields and properties, such as name, email, phone numbers, addresses, and more.

Contact Fields and Properties

idUnique identifier for the contact.
displayNameThe user-friendly name of the contact.
nameAn object containing the contact's name components (familyName, givenName, etc.).
emailsAn array of email addresses associated with the contact.
phoneNumbersAn array of phone numbers associated with the contact.
addressesAn array of addresses associated with the contact.

Creating Contacts

To create a new contact, use the create method of the navigator.contacts object.

navigator.contacts.create({ displayName: 'Jane Doe', phoneNumbers: [{ value: '555-555-5555' }] });

Editing Contacts

To edit an existing contact, use the update method of the contact object.

contact.displayName = 'Jane Smith';;

Deleting Contacts

To delete a contact, use the remove method of the contact object.


Searching Contacts

To search for contacts, use the find method of the navigator.contacts object.

navigator.contacts.find({ displayName: 'John*' }, (contacts) => { ... });

Sorting Contacts

To sort contacts, use the orderBy option in the find method.

navigator.contacts.find({ orderBy: 'displayName' }, (contacts) => { ... });

Next: HTML5 SMS and Telephony API

In the next session, we'll explore the HTML5 SMS and Telephony API, which empowers you to send and receive SMS messages and access telephony features from within your web applications. Follow us to learn more about this exciting technology!