42 lines
1.2 KiB
HTML
42 lines
1.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<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>
|