This repository was archived by the owner on Apr 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathweb-share.html
66 lines (59 loc) · 1.58 KB
/
web-share.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Web Share Demo</title>
</head>
<body>
<h1>
Web Share API
</h1>
<p>
More details can be found in the
<a
href="https://docs.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/open/?tabs=cmd-Windows"
>browsers devtools console</a
>
</p>
<button onclick="shareText()">
Share Text / URLs
</button>
<button onclick="shareFile()">
Share a File
</button>
<script>
async function shareText() {
if (navigator.share) {
try {
await navigator.share({
title: 'Sharing!',
text: 'Check this out',
url: 'https://www.pwabuilder.com',
});
}
catch (err) {
console.log('Error sharing', error);
}
}
}
async function shareFile() {
const test_file = new File(["some text..."], "filename.txt", {type: "text/plain"});
if (navigator.canShare && navigator.canShare({ files: [test_file] })) {
try {
await navigator.share({
files: [test_file],
title: 'Sharing a File',
text: 'Just sharing a file (:',
})
}
catch (err) {
console.log('Error sharing', error);
}
} else {
console.log(`Your system doesn't support sharing files.`);
}
}
</script>
</body>
</html>