diff --git a/app/server/public/js/core.js b/app/server/public/js/core.js index 50e1469..79a88d9 100644 --- a/app/server/public/js/core.js +++ b/app/server/public/js/core.js @@ -67,7 +67,8 @@ function fmtTime(ts) { // 跨天带日期,跨年再带年份 return (d.getFullYear() === now.getFullYear() ? md : d.getFullYear() + '/' + md) + ' ' + hm; } -// 剪贴板:WebView/局域网 http 非安全上下文没有 navigator.clipboard,降级 execCommand +// 剪贴板:优先 navigator.clipboard(https/localhost),失败时降级 execCommand。 +// 降级用 readonly textarea + 只 select 不 focus:不选焦点,手机上不弹软键盘。 async function copyText(text) { try { if (navigator.clipboard && window.isSecureContext) { await navigator.clipboard.writeText(text); return true; } @@ -75,8 +76,12 @@ async function copyText(text) { try { const ta = document.createElement('textarea'); ta.value = text; - ta.style.position = 'fixed'; ta.style.opacity = '0'; - document.body.appendChild(ta); ta.focus(); ta.select(); + ta.setAttribute('readonly', ''); + ta.style.position = 'fixed'; ta.style.top = '0'; ta.style.left = '-9999px'; + ta.style.opacity = '0'; + document.body.appendChild(ta); + ta.select(); + ta.setSelectionRange(0, ta.value.length); const ok = document.execCommand('copy'); document.body.removeChild(ta); return ok;