diff --git a/weed/admin/static/js/admin.js b/weed/admin/static/js/admin.js index 805445024..5d74f6e40 100644 --- a/weed/admin/static/js/admin.js +++ b/weed/admin/static/js/admin.js @@ -660,14 +660,46 @@ function formatDate(date) { return new Date(date).toLocaleString(); } -// Copy text to clipboard -function copyToClipboard(text) { - navigator.clipboard.writeText(text).then(() => { - showAlert('success', 'Copied to clipboard!'); - }).catch(err => { - console.error('Failed to copy text: ', err); +// Copy text to clipboard with fallback for non-secure contexts +function adminCopyToClipboard(text) { + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(text).then(() => { + showAlert('success', 'Copied to clipboard!'); + }).catch(err => { + console.error('Failed to copy text: ', err); + fallbackCopyText(text); + }); + } else { + fallbackCopyText(text); + } +} + +function fallbackCopyText(text) { + const textArea = document.createElement("textarea"); + textArea.value = text; + + // Ensure textArea is not visible but part of the DOM + textArea.style.position = "fixed"; + textArea.style.left = "-9999px"; + textArea.style.top = "0"; + document.body.appendChild(textArea); + + textArea.focus(); + textArea.select(); + + try { + const successful = document.execCommand('copy'); + if (successful) { + showAlert('success', 'Copied to clipboard!'); + } else { + showAlert('danger', 'Failed to copy to clipboard'); + } + } catch (err) { + console.error('Fallback copy failed: ', err); showAlert('danger', 'Failed to copy to clipboard'); - }); + } + + document.body.removeChild(textArea); } // Dashboard refresh functionality @@ -2359,7 +2391,7 @@ function createAccessKeysManagementContent(accessKeys) {
${key.access_key}
-