forked from mdn/dom-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
41 lines (34 loc) · 1.16 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Web share test</title>
<style>
</style>
</head>
<body>
<h1>Sharing MDN</h1>
<p>We love MDN, and want to share it as far as we can! Click the following button to share MDN's home page using your system's native share functionality. See the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share#Browser_compatibility">browsers this currently works on</a>.</p>
<p><button>Share MDN!</button></p>
<p class="result"></p>
<script>
let shareData = {
title: 'MDN',
text: 'Learn web development on MDN!',
url: 'https://developer.mozilla.org',
}
const btn = document.querySelector('button');
const resultPara = document.querySelector('.result');
btn.addEventListener('click', () => {
navigator.share(shareData)
.then(() =>
resultPara.textContent = 'MDN shared successfully'
)
.catch((e) =>
resultPara.textContent = 'Error: ' + e
)
});
</script>
</body>
</html>