Code: Select all
window.copyLinkWithText = (url, visibleText) => {
try {
const htmlSnippet = `[url=${url}]${visibleText}[/url]`;
const plainTextSnippet = url; // Just the URL in plain text
const blobHtml = new Blob([htmlSnippet], {
type: 'text/html'
});
const blobText = new Blob([plainTextSnippet], {
type: 'text/plain'
});
const clipboardItemInput = new ClipboardItem({
'text/html': blobHtml,
'text/plain': blobText
});
navigator.clipboard.write([clipboardItemInput])
.then(() => console.log("Copied both HTML and plain text to clipboard"))
.catch(err => console.error("Error copying to clipboard:", err));
} catch (ex) {
console.error("Exception in copyLinkWithText:", ex);
}
};