Add a contact to the mobile device Address book from an HTML webpage

Fredy31 picture Fredy31 · Dec 29, 2011 · Viewed 21.6k times · Source

I'm currently building a site where, with one touch, you should be able to add a contact to your IPhone/Android Address book. The website is currently HTML5, but Javascript and/or PhP options could be implemented.

So is there a way that on the click of a link, the mobile device will open the Adress book already filled with the info I want it to have (Name, EMail Address, Street Address, Phone number).

I've looked everywhere to only find ways to program apps that would do the same thing. I want to make it from a webpage. Anywhere I can learn how to do this?

PS: Currently, I'm trying with everything in a .VCF file that could be downloaded on the click... this seems to lead me nowhere at the moment.

Answer

Mohsen picture Mohsen · Dec 29, 2011

W3C defined Contacts API as a working draft but as far as I tested it's not supported in iOS devices(I have iPad with iOS4 and iPhone with iOS 5). You should test some android devices and tell us if they support Contacts API or not. That would be useful for future readers.

In case you have contacts api supported you can do this:

if(navigator.contacts){
   var mycontacts = [];
   navigator.contacts( ['emails.value', 'name', 'friends'],
                         function(contacts) { 
                           for(i in contacts) {

                               mycontacts.push(contacts[i]);

                         } );
}