-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpicker2.html
More file actions
77 lines (74 loc) · 2.3 KB
/
cpicker2.html
File metadata and controls
77 lines (74 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Contact Picker Demo</title>
<link href="https://fonts.googleapis.com/css2?family=Signika&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Signika', sans-serif;
background-color: #000;
color: #fff;
padding: 2rem;
}
h1 {
font-size: 1.8rem;
margin-bottom: 1rem;
}
button {
background: #ffd700;
color: #000;
padding: 0.6rem 1.2rem;
border: none;
border-radius: 8px;
font-size: 1rem;
cursor: pointer;
transition: background 0.3s;
}
button:hover {
background: #e6c200;
}
#result {
margin-top: 1.5rem;
padding: 1rem;
background: #111;
border: 1px solid #333;
border-radius: 8px;
word-break: break-word;
}
</style>
</head>
<body>
<h1>Contact Picker Demo</h1>
<p>Click below to pick a contact using the Contact Picker API:</p>
<button onclick="pickContact()">Pick a Contact</button>
<div id="result"></div>
<script>
async function pickContact() {
if ('contacts' in navigator && 'ContactsManager' in window) {
try {
const props = ['name', 'tel', 'email', 'address', 'icon'];
const opts = { multiple: false };
const contacts = await navigator.contacts.select(props, opts);
if (contacts.length === 0) {
document.getElementById('result').innerText = "No contact selected.";
return;
}
const contact = contacts[0];
document.getElementById('result').innerHTML = `
<strong>Name:</strong> ${contact.name ? contact.name.join(', ') : 'N/A'}<br>
<strong>Phone:</strong> ${contact.tel ? contact.tel.join(', ') : 'N/A'}<br>
<strong>Email:</strong> ${contact.email ? contact.email.join(', ') : 'N/A'}<br>
<strong>Address:</strong> ${contact.address ? JSON.stringify(contact.address) : 'N/A'}
`;
} catch (err) {
document.getElementById('result').innerText = "Error: " + err;
}
} else {
document.getElementById('result').innerText = "Contact Picker API not supported on this browser.";
}
}
</script>
</body>
</html>