Workaround
This workaround works when using the panel and HTML macros and optionally the excerpt and excerpt-include macros.
Add the following script to a HTML macro on the page you want to use the copy-to-clipboard functionality:
<script language="javascript">
function copyToClipboard(element) { $(element).parents().next("div:first").css("background-color", "#FFEBB0");
var $temp = $("<textarea>"); $("body").append($temp); $temp.val($(element).parents().next("div:first").clone().find('br').prepend('\r\n').end().text().trim()).select();
document.execCommand("copy");
$temp.remove(); }
</script>
Use the following script in a HTML macro just before the panel macro that contains the text that you wish to copy to clipboard. In some cases, you need to put this button and the panel with the contents to copy in a panel macro.
<button onclick="copyToClipboard($(this))">Copy to clipboard</button>
If you have multiple pages where you wish to use this method or multiple panel macros on the same page, you can place the two scripts above on separate pages in an excerpt macro, then use the excerpt-include macro to include them where needed.
Example
The following example shows the simplified use-case, using the script and the button on the same page as the panel to be copied.
{html}
<script language="javascript">
function copyToClipboard(element) { $(element).parents().next("div:first").css("background-color", "#FFEBB0");
var $temp = $("<textarea>");
$("body").append($temp); $temp.val($(element).parents().next("div:first").clone().find('br').prepend('\r\n').end().text().trim()).select();
document.execCommand("copy");
$temp.remove();
}
</script>
{html}
{html}
<button onclick="copyToClipboard($(this))">Copy to clipboard</button>
{html}
{panel}
<CONTENT TO BE COPIED HERE>
{panel}
Why is this card close? I would love to have this functionality in confluence and I do not seem to find anything that comes by default in confluence. We need this functionality.