JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Web Share Test</title>
</head>
<body>
<div>
<button onclick='share()'>Click Me</button>
</div>
</body>
</html>
JavaScript
function share() {
const blob = [
new Blob(['blah blah and blah'], {
type: 'text/plain'
})
];
const file = new File(blob, 'dummyFile.txt', {
lastModified: new Date(),
type: "text/plain"
});
if (navigator.share) {
navigator.share({
title: "File Sharig",
files: [file]
});
}
else {
console.log('navigator share not enabled.');
}
}