Add fallback for demo "Copy Link" functionality on browsers that do not support navigator.clipboard.

This commit is contained in:
David Anson 2020-04-09 20:35:32 -07:00
parent 678597485b
commit 214ecb5fb4

View file

@ -143,9 +143,12 @@
// Updates the URL hash and copies the URL to the clipboard // Updates the URL hash and copies the URL to the clipboard
function onCopyLinkClick(e) { function onCopyLinkClick(e) {
window.location.hash = encodeURIComponent(hashPrefix + markdown.value); window.location.hash = encodeURIComponent(hashPrefix + markdown.value);
/* eslint-disable-next-line no-unused-expressions */ if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard && navigator.clipboard.writeText &&
navigator.clipboard.writeText(window.location).then(noop, noop); navigator.clipboard.writeText(window.location).then(noop, noop);
} else {
/* eslint-disable-next-line no-alert */
alert("Document URL updated, select and copy it now.");
}
e.preventDefault(); e.preventDefault();
} }