Permalink
Find file
078629b Feb 24, 2017
93 lines (83 sloc) 3.4 KB
<!-- This work is licensed under the W3C Software and Document License
(http://www.w3.org/Consortium/Legal/2015/copyright-software-and-document).
-->
<html>
<head>
<title>Web Share Test</title>
<style>
.error {
color: #d22;
}
</style>
<!-- Origin Trial Token, feature = Web Share, origin = https://mgiuca.github.io, expires = 2017-04-06
This key allows navigator.share to work without a flag in Chrome on the
above origin only, for a limited time. Therefore, copying this code to
another site won't work, unless you also get an Origin Trial Token.
See https://github.com/jpchase/OriginTrials
-->
<meta http-equiv="origin-trial" data-feature="Web Share" data-expires="2017-04-06" content="ArCettX3kQ1JyWSaloWkanognaNFwxtrypRg1eDemUogl0q1Qc+FUIJuRFYgD14z155lNTT37FCGFrgUs2r3NwIAAABSeyJvcmlnaW4iOiJodHRwczovL21naXVjYS5naXRodWIuaW86NDQzIiwiZmVhdHVyZSI6IldlYlNoYXJlIiwiZXhwaXJ5IjoxNDkxNDk0ODQzfQ==">
</head>
<body>
<h1>Web Share Test</h1>
<table>
<tr><td>Title:</td><td><input id="title" value="The Title" size="40" /></td></tr>
<tr><td>Text:</td><td><input id="text" value="The message" size="40"/></td></tr>
<tr><td>URL:</td><td><input id="url" value="https://example.com" size="40"/></td></tr>
</table>
<p><input id="share" type="button" value="Share" />
<input id="share-no-gesture" type="button" value="Share without user gesture" /></p>
<div id="output"></div>
<p>This is a test page for the <a href="https://github.com/WICG/web-share">Web
Share API</a>. It will only work in browsers that have implemented the draft
proposal. At the time of writing, this works with:</p>
<ul>
<li>Google Chrome 55&ndash;57 for Android (limited trial; requires an <a
href="https://github.com/jpchase/OriginTrials">Origin Trial Token</a>).
</li>
<li>Google Chrome 54&ndash;57 for Android, with
chrome://flags#enable-experimental-web-platform-features enabled.</li>
</ul>
<script>
'use strict';
function logText(message, isError) {
if (isError)
console.error(message);
else
console.log(message);
var p = document.createElement('p');
if (isError)
p.setAttribute('class', 'error');
document.querySelector('#output').appendChild(p);
p.appendChild(document.createTextNode(message));
}
function logError(message) {
logText(message, true);
}
function testWebShare() {
if (navigator.share === undefined) {
logError('Error: Unsupported feature: navigator.share');
return;
}
var title = document.querySelector('#title').value;
var text = document.querySelector('#text').value;
var url = document.querySelector('#url').value;
navigator.share({title: title, text: text, url: url})
.then(() => logText('Successfully sent share'),
error => logError('Error sharing: ' + error));
}
function testWebShareDelay() {
setTimeout(testWebShare, 2000);
}
function onLoad() {
document.querySelector('#share').addEventListener('click', testWebShare);
document.querySelector('#share-no-gesture').addEventListener('click',
testWebShareDelay);
if (navigator.share === undefined) {
logError('Error: You need to use a browser that supports this draft ' +
'proposal.');
}
}
window.addEventListener('load', onLoad);
</script>
</body>
</html>