[fix]复制激活码页面滚动到底部

This commit is contained in:
枫落时 2024-11-21 11:54:27 +08:00
parent b455aa58fc
commit a824cdc497

View File

@ -74,16 +74,22 @@ $(document).ready(function() {
return navigator.clipboard.writeText(val); return navigator.clipboard.writeText(val);
} else { } else {
console.log(val); console.log(val);
const scrollX = window.scrollX;
const textArea = document.createElement('textarea') const textArea = document.createElement('textarea')
textArea.value = val textArea.value = val
// 使text area不在viewport同时设置不可见 // 使text area不在viewport同时设置不可见
document.body.appendChild(textArea) document.body.appendChild(textArea)
textArea.focus() textArea.focus()
textArea.select() textArea.select()
return new Promise((res, rej) => { try {
document.execCommand('copy') ? res() : rej() const result = document.execCommand('copy');
textArea.remove() return result ? Promise.resolve() : Promise.reject();
}) } catch (e) {
return Promise.reject(e);
} finally {
textArea.remove();
window.scrollTo(scrollX, 0);
}
} }
}; };