fix: copy button fallback for clipboard API failures (BUG-006)
This commit is contained in:
parent
53bebc0119
commit
bba19442f4
1 changed files with 16 additions and 3 deletions
|
|
@ -65,11 +65,24 @@ async function submitSignup() {
|
||||||
|
|
||||||
function copyKey() {
|
function copyKey() {
|
||||||
var key = document.getElementById('apiKeyDisplay').textContent;
|
var key = document.getElementById('apiKeyDisplay').textContent;
|
||||||
navigator.clipboard.writeText(key).then(function() {
|
var hint = document.querySelector('.copy-hint');
|
||||||
var hint = document.querySelector('.copy-hint');
|
function showCopied() {
|
||||||
hint.textContent = '✓ Copied!';
|
hint.textContent = '✓ Copied!';
|
||||||
setTimeout(function() { hint.textContent = 'Click to copy'; }, 2000);
|
setTimeout(function() { hint.textContent = 'Click to copy'; }, 2000);
|
||||||
});
|
}
|
||||||
|
try {
|
||||||
|
navigator.clipboard.writeText(key).then(showCopied).catch(function() {
|
||||||
|
// Fallback for older browsers / non-secure contexts
|
||||||
|
var ta = document.createElement('textarea');
|
||||||
|
ta.value = key; ta.style.position = 'fixed'; ta.style.opacity = '0';
|
||||||
|
document.body.appendChild(ta); ta.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(ta);
|
||||||
|
showCopied();
|
||||||
|
});
|
||||||
|
} catch(e) {
|
||||||
|
showCopied();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkout() {
|
async function checkout() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue