Created
September 21, 2011 01:48
-
-
Save macdonst/1230992 to your computer and use it in GitHub Desktop.
Contact Save Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Contact Example</title> | |
<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
// Wait for PhoneGap to load | |
// | |
document.addEventListener("deviceready", onDeviceReady, false); | |
// PhoneGap is ready | |
// | |
function onDeviceReady() { | |
// create | |
var contact = navigator.contacts.create(); | |
contact.displayName = "Plumber"; | |
contact.nickname = "Plumber"; //specify both to support all devices | |
var name = new ContactName(); | |
name.givenName = "Jane"; | |
name.familyName = "Doe"; | |
contact.name = name; | |
// save | |
contact.save(onSaveSuccess,onSaveError); | |
} | |
// onSaveSuccess: Get a snapshot of the current contacts | |
// | |
function onSaveSuccess(contact) { | |
alert("Save Success"); | |
} | |
// onSaveError: Failed to get the contacts | |
// | |
function onSaveError(contactError) { | |
alert("Error = " + contactError.code); | |
} | |
</script> | |
</head> | |
<body> | |
<h1>Example</h1> | |
<p>Find Contacts</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment