I'm going to use the contact plug-in in monaca, and I'm going to follow the example code.
<script>
function contacts_success(contacts){
alert(contacts.length)
+ 'contacts returned.'
+ ( contacts [2] & contacts [2].name ?
('Third contact is' + contacts[2].name.formatted):
''));
}
function contacts_failed(msgObject){
alert("Failed to access contact list:" + JSON.stringify(msgObject)));
}
function get_contacts(){
varobj = new ContactFindOptions();
obj.filter="";
obj.multiple=true;
navigator.contacts.find(
["displayName", "name", contacts_success,
contacts_failed, obj);
}
</script>
</head>
<body>
<a href="#" class="btn large" onclick="get_contacts();return false;">Get Phone's Contacts</a>
</body>
was successfully executed.I want to do this when it boots up.
<script>
function contacts_success(contacts){
alert(contacts.length)
+ 'contacts returned.'
+ ( contacts [2] & contacts [2].name? ('Third contact is' + contacts [2].name.formatted)
: ''));
}
function contacts_failed(msgObject){
alert("Failed to access contact list:" + JSON.stringify(msgObject)));
}
varobj = new ContactFindOptions();
obj.filter="";
obj.multiple=true;
navigator.contacts.find(
["displayName", "name", contacts_success,
contacts_failed, obj);
</script>
but
Uncaught ReferenceError: ContactFindOptions is not defined
The error occurred.
I wonder why...
ContactFindOptions
This may be because the process runs before loading the file (Cordova) that defines it.
// Wait for Cordova to finish loading
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova Ready
//
function onDeviceReady() {
varobj = new ContactFindOptions();
obj.filter="";
obj.multiple=true;
navigator.contacts.find(
["displayName", "name",
contacts_success, contacts_failed, obj);
}
and so on.
cf.Contact Us - Monaca Document
© 2024 OneMinuteCode. All rights reserved.